之前的帖子添加串口重定向组件,实现串口输出。PSOC Edge E84 AI Kit带有Wifi蓝牙双模无线模块,通过添加RTOS、Lwip、Wifi-Host-Driver等组件,实现Wifi扫描无线连接点的功能。
1、硬件相关查看开发板的原理图,Wifi蓝牙双模模块和PSOC Edge E84芯片的引脚连接图如下。MCU通过SDIO(Secure Digital Input Output)接口控制Wifi,通过UART HCI接口控制蓝牙部分。

BSP Assistant的Devices部分的设置和原理图的硬件部分对应。

Device Configurator中已适配硬件的接口,能直接生成相应的驱动代码。
2、添加Wifi模块组件PSOC Edge E84 MCU与无线模块的Wifi模块控制方式如下,通过主从通讯的模式控制无线模块的Wifi模块。

ModusToolbox的Library Manager中通过添加wifi-core-freertos-lwip-mbedtls组合库,添加wifi host driver、freertos、lwip等库到proj_cm33_ns中。

proj_cm33_ns工程的Makefile文件中添加组件名称、库相关的宏定义以及参数配置如下,添加FreeRTOS、LWIP、MBEDTLS功能支持。
COMPONENTS+=FREERTOS LWIP MBEDTLS # Custom configuration of mbedtls library. MBEDTLSFLAGS = MBEDTLS_USER_CONFIG_FILE='"configs/mbedtls_user_config.h"' # Add additional defines to the build process (without a leading -D). DEFINES+=$(MBEDTLSFLAGS) CYBSP_WIFI_CAPABLE CY_RETARGET_IO_CONVERT_LF_TO_CRLF CY_RTOS_AWARE # Default configuration of mbedtls library. DEFINES+=MBEDTLS_CONFIG_FILE='"mbedtls/mbedtls_config.h"' # PSA configuration of mbedtls library. DEFINES+=MBEDTLS_PSA_CRYPTO_CONFIG_FILE='"configs/ifx_psa_crypto_config.h"'3、Wifi Scan相关的代码
工程使用FreeRTOS,添加FreeRTOSConfig.h,用于配置FreeRTOS和适配cy_rtos库接口。
#ifndef FREERTOS_CONFIG_H
#define FREERTOS_CONFIG_H
/*-----------------------------------------------------------
* Application specific definitions.
*
* These definitions should be adjusted for your particular hardware and
* application requirements.
*
* THESE PARAMETERS ARE DESCRIBED WITHIN THE 'CONFIGURATION' SECTION OF THE
* FreeRTOS API DOCUMENTATION AVAILABLE ON THE FreeRTOS.org WEB SITE.
*
* See http://www.freertos.org/a00110.html.
*----------------------------------------------------------*/
#if defined (__ICCARM__) || (__GNUC__)
#include "cy_utils.h"
/* Get the low power configuration parameters from
* the ModusToolbox Device Configurator GeneratedSource:
* CY_CFG_PWR_SYS_IDLE_MODE - System Idle Power Mode
* CY_CFG_PWR_DEEPSLEEP_LATENCY - Deep Sleep Latency (ms)
*/
#include "cycfg_system.h"
#include "cy_device_headers.h"
#endif
#define configUSE_PREEMPTION 1
#define configUSE_PORT_OPTIMISED_TASK_SELECTION 0
#if defined (__ICCARM__) || (__GNUC__)
extern uint32_t SystemCoreClock;
#endif
#define configCPU_CLOCK_HZ SystemCoreClock
#define configTICK_RATE_HZ ((TickType_t ) 1000)
#define configMAX_PRIORITIES 7
/* Increase the stack size to 256 to support ds-ram feature */
#define configMINIMAL_STACK_SIZE 256
#define configMAX_TASK_NAME_LEN 16
#define configUSE_16_BIT_TICKS 0
#define configIDLE_SHOULD_YIELD 1
#define configUSE_TASK_NOTIFICATIONS 1
#define configUSE_MUTEXES 1
#define configUSE_RECURSIVE_MUTEXES 1
#define configUSE_COUNTING_SEMAPHORES 1
#define configQUEUE_REGISTRY_SIZE 10
#define configUSE_QUEUE_SETS 0
#define configUSE_TIME_SLICING 1
#define configENABLE_BACKWARD_COMPATIBILITY 0
#define configNUM_THREAD_LOCAL_STORAGE_POINTERS 5
/* Compile-time macros to enable or disable TrustZone, Memory Protection Unit (MPU) and Floating Point Unit (FPU) support. */
/* configENABLE_FPU is set to 0 for the platforms which doesnt support hardware FPU and
when application makefile has VFP_SELECT configured as softfloat */
#if defined(COMPONENT_CYW20829) || defined(COMPONENT_CYW89829) || defined(MTB_SOFTFLOAT)
#define configENABLE_FPU 0
#else
#define configENABLE_FPU 1
#endif
#define configENABLE_MPU 0
#define configENABLE_TRUSTZONE 0
#if defined (COMPONENT_SECURE_DEVICE)
#define configRUN_FREERTOS_SECURE_ONLY 1
#else
#define configRUN_FREERTOS_SECURE_ONLY 0
#endif
/* Memory allocation related definitions. */
#define configSUPPORT_STATIC_ALLOCATION 1
#define configSUPPORT_DYNAMIC_ALLOCATION 1
#define configTOTAL_HEAP_SIZE ((size_t )(50*1024))
#define configAPPLICATION_ALLOCATED_HEAP 0
/* Hook function related definitions. */
#define configUSE_IDLE_HOOK 0
#define configUSE_TICK_HOOK 0
#define configCHECK_FOR_STACK_OVERFLOW 2
#define configUSE_MALLOC_FAILED_HOOK 1
#define configUSE_DAEMON_TASK_STARTUP_HOOK 0
/* Run time and task stats gathering related definitions. */
#define configGENERATE_RUN_TIME_STATS 0
#define configUSE_TRACE_FACILITY 1
#define configUSE_STATS_FORMATTING_FUNCTIONS 0
/* Co-routine related definitions. */
#define configUSE_CO_ROUTINES 0
#define configMAX_CO_ROUTINE_PRIORITIES 1
/* Software timer related definitions. */
#define configUSE_TIMERS 1
#define configTIMER_TASK_PRIORITY 3
#define configTIMER_QUEUE_LENGTH 10
#define configTIMER_TASK_STACK_DEPTH ( configMINIMAL_STACK_SIZE * 2 )
/*
configMAX_SYSCALL_INTERRUPT_PRIORITY sets the highest interrupt priority from which
interrupt safe FreeRTOS API functions can be called.
!!!! configMAX_SYSCALL_INTERRUPT_PRIORITY must not be set to zero !!!!
See http://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html
*/
#if defined(COMPONENT_SECURE_DEVICE) || defined(COMPONENT_CYW20829) || defined(COMPONENT_CYW89829)
#define configMAX_SYSCALL_INTERRUPT_PRIORITY 0x3F
#else
#define configMAX_SYSCALL_INTERRUPT_PRIORITY 0x40
#endif
/* configMAX_API_CALL_INTERRUPT_PRIORITY is a new name for configMAX_SYSCALL_INTERRUPT_PRIORITY
that is used by newer ports only. The two are equivalent. */
#define configMAX_API_CALL_INTERRUPT_PRIORITY configMAX_SYSCALL_INTERRUPT_PRIORITY
/* Set the following definitions to 1 to include the API function, or zero
to exclude the API function. */
#define INCLUDE_vTaskPrioritySet 1
#define INCLUDE_uxTaskPriorityGet 1
#define INCLUDE_vTaskDelete 1
#define INCLUDE_vTaskCleanUpResources 0
#define INCLUDE_vTaskSuspend 1
#define INCLUDE_xResumeFromISR 1
#define INCLUDE_vTaskDelayUntil 1
#define INCLUDE_vTaskDelay 1
#define INCLUDE_xTaskGetSchedulerState 1
#define INCLUDE_xTaskGetCurrentTaskHandle 1
#define INCLUDE_uxTaskGetStackHighWaterMark 0
#define INCLUDE_xTaskGetIdleTaskHandle 0
#define INCLUDE_eTaskGetState 0
#define INCLUDE_xEventGroupSetBitFromISR 1
#define INCLUDE_xTimerPendFunctionCall 1
#define INCLUDE_xTaskAbortDelay 0
#define INCLUDE_xTaskGetHandle 0
#define INCLUDE_xTaskResumeFromISR 1
/* Normal assert() semantics without relying on the provision of an assert.h
header file. */
#if defined(NDEBUG)
#define configASSERT( x ) CY_UNUSED_PARAMETER( x )
#else
#define configASSERT( x ) if( ( x ) == 0 ) { taskDISABLE_INTERRUPTS(); CY_HALT(); }
#endif
/* Definitions that map the FreeRTOS port interrupt handlers to their CMSIS
standard names - or at least those used in the unmodified vector table. */
#define vPortSVCHandler SVC_Handler
#define xPortPendSVHandler PendSV_Handler
#define xPortSysTickHandler SysTick_Handler
/* Dynamic Memory Allocation Schemes */
#define HEAP_ALLOCATION_TYPE1 (1) /* heap_1.c*/
#define HEAP_ALLOCATION_TYPE2 (2) /* heap_2.c*/
#define HEAP_ALLOCATION_TYPE3 (3) /* heap_3.c*/
#define HEAP_ALLOCATION_TYPE4 (4) /* heap_4.c*/
#define HEAP_ALLOCATION_TYPE5 (5) /* heap_5.c*/
#define NO_HEAP_ALLOCATION (0)
#define configHEAP_ALLOCATION_SCHEME (HEAP_ALLOCATION_TYPE3)
/* Check if the ModusToolbox Device Configurator Power personality parameter
* "System Idle Power Mode" is set to either "CPU Sleep" or "System Deep Sleep".
*/
#if defined(CY_CFG_PWR_SYS_IDLE_MODE) && \
((CY_CFG_PWR_SYS_IDLE_MODE == CY_CFG_PWR_MODE_SLEEP) || \
(CY_CFG_PWR_SYS_IDLE_MODE == CY_CFG_PWR_MODE_DEEPSLEEP) || \
(CY_CFG_PWR_SYS_IDLE_MODE == CY_CFG_PWR_MODE_DEEPSLEEP_RAM))
/* Enable low power tickless functionality. The RTOS abstraction library
* provides the compatible implementation of the vApplicationSleep hook:
* https://github.com/Infineon/abstraction-rtos#freertos
* The Low Power Assistant library provides additional portable configuration layer
* for low-power features supported by the PSoC 6 devices:
* https://github.com/Infineon/lpa
*/
extern void vApplicationSleep( uint32_t xExpectedIdleTime );
#define portSUPPRESS_TICKS_AND_SLEEP( xIdleTime ) vApplicationSleep( xIdleTime )
#define configUSE_TICKLESS_IDLE 2
#else
#define configUSE_TICKLESS_IDLE 0
#endif
/* Deep Sleep Latency Configuration */
#if ( CY_CFG_PWR_DEEPSLEEP_LATENCY > 0 )
#define configEXPECTED_IDLE_TIME_BEFORE_SLEEP CY_CFG_PWR_DEEPSLEEP_LATENCY
#endif
/* Allocate newlib reeentrancy structures for each RTOS task.
* The system behavior is toolchain-specific.
*
* GCC toolchain: the application must provide the implementation for the required
* newlib hook functions: __malloc_lock, __malloc_unlock, __env_lock, __env_unlock.
* FreeRTOS-compatible implementation is provided by the clib-support library:
* https://github.com/Infineon/clib-support
*
* ARM/IAR toolchains: the application must provide the reent.h header to adapt
* FreeRTOS's configUSE_NEWLIB_REENTRANT to work with the toolchain-specific C library.
* The compatible implementations are also provided by the clib-support library.
*/
#if defined(__llvm__) && !defined(__ARMCC_VERSION)
#define configUSE_PICOLIBC_TLS 1
#else
#define configUSE_NEWLIB_REENTRANT 1
#endif /* #if defined(__llvm__) && !defined(__ARMCC_VERSION) */
#endif /* FREERTOS_CONFIG_H */实现Wifi Scan功能,需要调用Wi-Fi Connection Manager驱动库中的函数,包含cy_wcm.h头文件用于调用其中的驱动函数,并定义 Wifi Scan相关的宏定义和函数声明如下。
"scan_task.h"
#ifndef SOURCE_SCAN_TASK_H_
#define SOURCE_SCAN_TASK_H_
#if defined(__cplusplus)
extern "C" {
#endif /* __cplusplus */
/*******************************************************************************
* Header file includes
*******************************************************************************/
#include "FreeRTOS.h"
#include "task.h"
#include "cy_wcm.h"
#include <stdio.h>
#include <queue.h>
/*******************************************************************************
* Macros
*******************************************************************************/
/* The delay in milliseconds between successive scans.*/
#define SCAN_DELAY_MS (3000U)
#define SCAN_TASK_STACK_SIZE (4096U)
#define SCAN_TASK_PRIORITY (3U)
#define MAX_SECURITY_STRING_LENGTH (15U)
#define SECURITY_OPEN "OPEN"
#define SECURITY_WEP_PSK "WEP-PSK"
#define SECURITY_WEP_SHARED "WEP-SHARED"
#define SECURITY_WEP_TKIP_PSK "WEP-TKIP-PSK"
#define SECURITY_WPA_TKIP_PSK "WPA-TKIP-PSK"
#define SECURITY_WPA_AES_PSK "WPA-AES-PSK"
#define SECURITY_WPA_MIXED_PSK "WPA-MIXED-PSK"
#define SECURITY_WPA2_AES_PSK "WPA2-AES-PSK"
#define SECURITY_WPA2_TKIP_PSK "WPA2-TKIP-PSK"
#define SECURITY_WPA2_MIXED_PSK "WPA2-MIXED-PSK"
#define SECURITY_WPA2_FBT_PSK "WPA2-FBT-PSK"
#define SECURITY_WPA3_SAE "WPA3-SAE"
#define SECURITY_WPA2_WPA_AES_PSK "WPA2-WPA-AES-PSK"
#define SECURITY_WPA2_WPA_MIXED_PSK "WPA2-WPA-MIXED-PSK"
#define SECURITY_WPA3_WPA2_PSK "WPA3-WPA2-PSK"
#define SECURITY_WPA_TKIP_ENT "WPA-TKIP-ENT"
#define SECURITY_WPA_AES_ENT "WPA-AES-ENT"
#define SECURITY_WPA_MIXED_ENT "WPA-MIXED-ENT"
#define SECURITY_WPA2_TKIP_ENT "WPA2-TKIP-ENT"
#define SECURITY_WPA2_AES_ENT "WPA2-AES-ENT"
#define SECURITY_WPA2_MIXED_ENT "WPA2-MIXED-ENT"
#define SECURITY_WPA2_FBT_ENT "WPA2-FBT-ENT"
#define SECURITY_IBSS_OPEN "IBSS-OPEN"
#define SECURITY_WPS_SECURE "WPS-SECURE"
#define SECURITY_UNKNOWN "UNKNOWN"
#define PRINT_SCAN_TEMPLATE() \
printf("\n----------------------------------------------" \
"------------------------------------------------------\n" \
" # SSID RSSI Channel " \
" MAC Address Security\n" \
"--------------------------------------------------------" \
"--------------------------------------------\n");
#define APP_INFO( x ) do { printf("\nInfo: "); printf x;} while(0);
/*******************************************************************************
* Global Variables
*******************************************************************************/
/* Network connection task handle */
extern TaskHandle_t scan_task_handle;
/*******************************************************************************
* Function Prototypes
*******************************************************************************/
void scan_task(void* arg);
#if defined(__cplusplus)
}
#endif /* __cplusplus */
#endif /* SOURCE_SCAN_TASK_H_ */`"scan_task.c"定义sdio接口和Wifi 相关的变量
#define RESET_VAL (0U)
#define ULVALUE_DATA (0U)
#define BITS_TO_CLEARONENTRY (0U)
#define BITS_TO_CLEARONEXIT (0U)
#define APP_SDIO_INTERRUPT_PRIORITY (7U)
#define APP_HOST_WAKE_INTERRUPT_PRIORITY (2U)
#define APP_SDIO_FREQUENCY_HZ (25000000U)
#define SDHC_SDIO_64BYTES_BLOCK (64U)
static mtb_hal_sdio_t sdio_instance;
cy_stc_sd_host_context_t sdhc_host_context;
static cy_wcm_config_t wcm_config;
#if (CY_CFG_PWR_SYS_IDLE_MODE == CY_CFG_PWR_MODE_DEEPSLEEP)
/* SysPm callback parameter structure for SDHC */
static cy_stc_syspm_callback_params_t sdcardDSParams =
{
.context = &sdhc_host_context,
.base = CYBSP_WIFI_SDIO_HW
};
/* SysPm callback structure for SDHC*/
static cy_stc_syspm_callback_t sdhcDeepSleepCallbackHandler =
{
.callback = Cy_SD_Host_DeepSleepCallback,
.skipMode = SYSPM_SKIP_MODE,
.type = CY_SYSPM_DEEPSLEEP,
.callbackParams = &sdcardDSParams,
.prevItm = NULL,
.nextItm = NULL,
.order = SYSPM_CALLBACK_ORDER
};
#endifSDIO接口的中断处理以及接口的初始化定义如下,初始化HOST SDIO模块、使能Wifi内部的变压器用于模块供电、设置Host Wake Up中断,完成SDIO接口的初始化过程。
/*******************************************************************************
* Function Name: sdio_interrupt_handler
********************************************************************************
* Summary:
* Interrupt handler function for SDIO instance.
*******************************************************************************/
static void sdio_interrupt_handler(void)
{
mtb_hal_sdio_process_interrupt(&sdio_instance);
}
/*******************************************************************************
* Function Name: host_wake_interrupt_handler
********************************************************************************
* Summary:
* Interrupt handler function for the host wake up input pin.
*******************************************************************************/
static void host_wake_interrupt_handler(void)
{
mtb_hal_gpio_process_interrupt(&wcm_config.wifi_host_wake_pin);
}
/*******************************************************************************
* Function Name: app_sdio_init
********************************************************************************
* Summary:
* This function configures and initializes the SDIO instance used in
* communication between the host MCU and the wireless device.
*******************************************************************************/
static void app_sdio_init(void)
{
cy_rslt_t result;
mtb_hal_sdio_cfg_t sdio_hal_cfg;
cy_stc_sysint_t sdio_intr_cfg =
{
.intrSrc = CYBSP_WIFI_SDIO_IRQ,
.intrPriority = APP_SDIO_INTERRUPT_PRIORITY
};
cy_stc_sysint_t host_wake_intr_cfg =
{
.intrSrc = CYBSP_WIFI_HOST_WAKE_IRQ,
.intrPriority = APP_HOST_WAKE_INTERRUPT_PRIORITY
};
/* Initialize the SDIO interrupt and specify the interrupt handler. */
cy_en_sysint_status_t interrupt_init_status = Cy_SysInt_Init(&sdio_intr_cfg, sdio_interrupt_handler);
/* SDIO interrupt initialization failed. Stop program execution. */
if(CY_SYSINT_SUCCESS != interrupt_init_status)
{
handle_app_error();
}
/* Enable NVIC interrupt. */
NVIC_EnableIRQ(CYBSP_WIFI_SDIO_IRQ);
/* Setup SDIO using the HAL object and desired configuration */
result = mtb_hal_sdio_setup(&sdio_instance, &CYBSP_WIFI_SDIO_sdio_hal_config, NULL, &sdhc_host_context);
/* SDIO setup failed. Stop program execution. */
if(CY_RSLT_SUCCESS != result)
{
handle_app_error();
}
/* Initialize and Enable SD HOST */
Cy_SD_Host_Enable(CYBSP_WIFI_SDIO_HW);
Cy_SD_Host_Init(CYBSP_WIFI_SDIO_HW, CYBSP_WIFI_SDIO_sdio_hal_config.host_config, &sdhc_host_context);
Cy_SD_Host_SetHostBusWidth(CYBSP_WIFI_SDIO_HW, CY_SD_HOST_BUS_WIDTH_4_BIT);
sdio_hal_cfg.frequencyhal_hz = APP_SDIO_FREQUENCY_HZ;
sdio_hal_cfg.block_size = SDHC_SDIO_64BYTES_BLOCK;
/* Configure SDIO */
mtb_hal_sdio_configure(&sdio_instance, &sdio_hal_cfg);
#if (CY_CFG_PWR_SYS_IDLE_MODE == CY_CFG_PWR_MODE_DEEPSLEEP)
/* SDHC SysPm callback registration */
Cy_SysPm_RegisterCallback(&sdhcDeepSleepCallbackHandler);
#endif /* (CY_CFG_PWR_SYS_IDLE_MODE == CY_CFG_PWR_MODE_DEEPSLEEP) */
/* Setup GPIO using the HAL object for WIFI WL REG ON */
mtb_hal_gpio_setup(&wcm_config.wifi_wl_pin, CYBSP_WIFI_WL_REG_ON_PORT_NUM, CYBSP_WIFI_WL_REG_ON_PIN);
/* Setup GPIO using the HAL object for WIFI HOST WAKE PIN */
mtb_hal_gpio_setup(&wcm_config.wifi_host_wake_pin, CYBSP_WIFI_HOST_WAKE_PORT_NUM, CYBSP_WIFI_HOST_WAKE_PIN);
/* Initialize the Host wakeup interrupt and specify the interrupt handler. */
cy_en_sysint_status_t interrupt_init_status_host_wake = Cy_SysInt_Init(&host_wake_intr_cfg, host_wake_interrupt_handler);
/* Host wake up interrupt initialization failed. Stop program execution. */
if(CY_SYSINT_SUCCESS != interrupt_init_status_host_wake)
{
handle_app_error();
}
/* Enable NVIC interrupt. */
NVIC_EnableIRQ(CYBSP_WIFI_HOST_WAKE_IRQ);
}scan_task.c中调用sdio模块初始化函数和wifi连接管理模块的初始化函数,cy_wcm_start_scan函数启动Wifi Scan流程,并注册回调函数scan_callback用于处理Wifi Scan的结果
void scan_task(void *arg)
{
cy_wcm_scan_filter_t scan_filter;
cy_rslt_t result = CY_RSLT_SUCCESS;
cy_wcm_mac_t scan_for_mac_value = {SCAN_FOR_MAC_ADDRESS};
memset(&scan_filter, RESET_VAL, sizeof(cy_wcm_scan_filter_t));
app_sdio_init();
/* Initialize wcm */
wcm_config.interface = CY_WCM_INTERFACE_TYPE_STA;
wcm_config.wifi_interface_instance = &sdio_instance;
result = cy_wcm_init(&wcm_config);
if(CY_RSLT_SUCCESS != result)
{
handle_app_error();
}
while (true)
{
PRINT_SCAN_TEMPLATE();
result = cy_wcm_start_scan(scan_callback, NULL, NULL);
/* Wait for scan completion if scan was started successfully. The API
* cy_wcm_start_scan doesn't wait for scan completion. If it is called
* again when the scan hasn't completed, the API returns
* CY_WCM_RESULT_SCAN_IN_PROGRESS.
*/
if (CY_RSLT_SUCCESS == result)
{
xTaskNotifyWait(BITS_TO_CLEARONENTRY, BITS_TO_CLEARONEXIT, NULL,
portMAX_DELAY);
}
vTaskDelay(pdMS_TO_TICKS(SCAN_DELAY_MS));
}
}scan_callback的定义以及相关信息的打印函数如下,扫描到一个Wifi热点,将其信息通过串口打印到串口终端,完成扫描通过调用异步功能函数xTaskNotify(scan_task_handle, ULVALUE_DATA, eNoAction);通知主函数扫描完成。
/*******************************************************************************
* Function Name: print_scan_result
********************************************************************************
* Summary: This function prints the scan result accumulated by the scan
* handler.
*
* Parameters:
* cy_wcm_scan_result_t *result: Pointer to the scan result.
*
* Return:
* void
*
*******************************************************************************/
static void print_scan_result(cy_wcm_scan_result_t *result)
{
char* security_type_string;
/* Convert the security type of the scan result to the corresponding
* security string
*/
switch (result->security)
{
case CY_WCM_SECURITY_OPEN:
security_type_string = SECURITY_OPEN;
break;
case CY_WCM_SECURITY_WEP_PSK:
security_type_string = SECURITY_WEP_PSK;
break;
case CY_WCM_SECURITY_WEP_SHARED:
security_type_string = SECURITY_WEP_SHARED;
break;
case CY_WCM_SECURITY_WPA_TKIP_PSK:
security_type_string = SECURITY_WEP_TKIP_PSK;
break;
case CY_WCM_SECURITY_WPA_AES_PSK:
security_type_string = SECURITY_WPA_AES_PSK;
break;
case CY_WCM_SECURITY_WPA_MIXED_PSK:
security_type_string = SECURITY_WPA_MIXED_PSK;
break;
case CY_WCM_SECURITY_WPA2_AES_PSK:
security_type_string = SECURITY_WPA2_AES_PSK;
break;
case CY_WCM_SECURITY_WPA2_TKIP_PSK:
security_type_string = SECURITY_WPA2_TKIP_PSK;
break;
case CY_WCM_SECURITY_WPA2_MIXED_PSK:
security_type_string = SECURITY_WPA2_MIXED_PSK;
break;
case CY_WCM_SECURITY_WPA2_FBT_PSK:
security_type_string = SECURITY_WPA2_FBT_PSK;
break;
case CY_WCM_SECURITY_WPA3_SAE:
security_type_string = SECURITY_WPA3_SAE;
break;
case CY_WCM_SECURITY_WPA3_WPA2_PSK:
security_type_string = SECURITY_WPA3_WPA2_PSK;
break;
case CY_WCM_SECURITY_IBSS_OPEN:
security_type_string = SECURITY_IBSS_OPEN;
break;
case CY_WCM_SECURITY_WPS_SECURE:
security_type_string = SECURITY_WPS_SECURE;
break;
case CY_WCM_SECURITY_UNKNOWN:
security_type_string = SECURITY_UNKNOWN;
break;
case CY_WCM_SECURITY_WPA2_WPA_AES_PSK:
security_type_string = SECURITY_WPA2_WPA_AES_PSK;
break;
case CY_WCM_SECURITY_WPA2_WPA_MIXED_PSK:
security_type_string = SECURITY_WPA2_WPA_MIXED_PSK;
break;
case CY_WCM_SECURITY_WPA_TKIP_ENT:
security_type_string = SECURITY_WPA_TKIP_ENT;
break;
case CY_WCM_SECURITY_WPA_AES_ENT:
security_type_string = SECURITY_WPA_AES_ENT;
break;
case CY_WCM_SECURITY_WPA_MIXED_ENT:
security_type_string = SECURITY_WPA_MIXED_ENT;
break;
case CY_WCM_SECURITY_WPA2_TKIP_ENT:
security_type_string = SECURITY_WPA2_TKIP_ENT;
break;
case CY_WCM_SECURITY_WPA2_AES_ENT:
security_type_string = SECURITY_WPA2_AES_ENT;
break;
case CY_WCM_SECURITY_WPA2_MIXED_ENT:
security_type_string = SECURITY_WPA2_MIXED_ENT;
break;
case CY_WCM_SECURITY_WPA2_FBT_ENT:
security_type_string = SECURITY_WPA2_FBT_ENT;
break;
default:
security_type_string = SECURITY_UNKNOWN;
break;
}
printf(" %2"PRIu32" %-32s %4d %2d %02X:%02X:%02X:%02X:%02X:%02X %-15s\n",
num_scan_result, result->SSID,
result->signal_strength, result->channel, result->BSSID[0],
result->BSSID[1],result->BSSID[2], result->BSSID[3],
result->BSSID[4], result->BSSID[5],
security_type_string);
}
/*******************************************************************************
* Function Name: scan_callback
********************************************************************************
* Summary: The callback function which accumulates the scan results. After
* completing the scan, it sends a task notification to scan_task.
*
* Parameters:
* cy_wcm_scan_result_t *result_ptr: Pointer to the scan result
* void *user_data: User data.
* cy_wcm_scan_status_t status: Status of scan completion.
*
* Return:
* void
*
*******************************************************************************/
static void scan_callback(cy_wcm_scan_result_t *result_ptr, void *user_data,
cy_wcm_scan_status_t status)
{
uint8_t ssid_len = RESET_VAL;
if(NULL != result_ptr)
{
ssid_len = strlen((const char *)result_ptr->SSID);
}
if ((RESET_VAL != ssid_len) && (status == CY_WCM_SCAN_INCOMPLETE))
{
/* Increment the number of scan results and print the result*/
num_scan_result++;
print_scan_result(result_ptr);
}
if ((CY_WCM_SCAN_COMPLETE == status) )
{
/* Reset the number of scan results to 0 for the next scan.*/
num_scan_result = RESET_VAL;
/* Notify that scan has completed.*/
xTaskNotify(scan_task_handle, ULVALUE_DATA, eNoAction);
}
}编译和烧录到开发板,通过串口查看输出的Wifi扫描结果

我要赚赏金
