Skip to content

Commit c3f1817

Browse files
Rex-Chen-NXPmmahadevan108
authored andcommitted
mcux: wifi_nxp: Add libcsi feature
CSI feaure switch to use static library. Signed-off-by: Rex Chen <rex.chen_1@nxp.com>
1 parent 6c46b1b commit c3f1817

28 files changed

+1596
-9410
lines changed

mcux/middleware/wifi_nxp/CMakeLists.txt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,22 @@ else()
1212
set(MCUX_SDK_DIR ${ZEPHYR_HAL_NXP_MODULE_DIR}/mcux/mcux-sdk-ng)
1313
endif()
1414

15+
if(CONFIG_NXP_WIFI_CSI_AMI)
16+
add_library(libcsi STATIC IMPORTED)
17+
if(CONFIG_NXP_LIBCSI_CM33)
18+
set_target_properties(libcsi PROPERTIES IMPORTED_LOCATION ${ZEPHYR_HAL_NXP_MODULE_DIR}/zephyr/blobs/libcsi/cm33/libcsi.a)
19+
elseif(CONFIG_NXP_LIBCSI_CM7_20M)
20+
set_target_properties(libcsi PROPERTIES IMPORTED_LOCATION ${ZEPHYR_HAL_NXP_MODULE_DIR}/zephyr/blobs/libcsi/cm7/cm7f_sta_20_only/libcsi.a)
21+
else()
22+
set_target_properties(libcsi PROPERTIES IMPORTED_LOCATION ${ZEPHYR_HAL_NXP_MODULE_DIR}/zephyr/blobs/libcsi/cm7/cm7f/libcsi.a)
23+
endif()
24+
target_include_directories(app PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/libcsi/incl)
25+
zephyr_include_directories(
26+
libcsi/incl
27+
)
28+
target_link_libraries(app PRIVATE libcsi)
29+
endif()
30+
1531
zephyr_compile_definitions_ifdef(CONFIG_NXP_88W8987
1632
SD8987
1733
)

mcux/middleware/wifi_nxp/incl/nxp_wifi.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,10 @@ extern "C" {
118118
#define CONFIG_CSI 1
119119
#endif
120120

121+
#if CONFIG_NXP_WIFI_CSI_AMI
122+
#define CONFIG_CSI_AMI 1
123+
#endif
124+
121125
#if CONFIG_NXP_WIFI_RESET
122126
#define CONFIG_WIFI_RESET 1
123127
#endif

mcux/middleware/wifi_nxp/incl/wifidriver/wifi_events.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,9 @@ enum wifi_event
170170
/* Recv csi data */
171171
WIFI_EVENT_CSI,
172172
WIFI_EVENT_CSI_STATUS,
173+
#if CONFIG_CSI_AMI
174+
WIFI_EVENT_CSI_PROC,
175+
#endif
173176
#endif
174177
#if (CONFIG_11MC) || (CONFIG_11AZ)
175178
/* Event to trigger or stop ftm*/

mcux/middleware/wifi_nxp/incl/wlcmgr/wlan.h

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,22 @@ enum wlan_csi_opt
519519
CSI_FILTER_OPT_CLEAR,
520520
CSI_FILTER_OPT_DUMP,
521521
};
522+
523+
#if CONFIG_CSI_AMI
524+
typedef struct _wlan_csi_proc_cfg
525+
{
526+
/** peer mac address */
527+
uint8_t peer_mac[MLAN_MAC_ADDR_LENGTH];
528+
/** Number of CSI to process */
529+
uint8_t num_csi;
530+
/** CSI bandwidth: 20/40/80 */
531+
uint8_t packet_bandwidth;
532+
/** CSI format: legacy/HT/VHT/HE */
533+
uint8_t packet_format;
534+
/** Reference Update */
535+
uint8_t reference_update;
536+
} wlan_csi_proc_cfg;
537+
#endif
522538
#endif
523539

524540
#if CONFIG_NET_MONITOR
@@ -6781,6 +6797,23 @@ int wlan_register_csi_user_callback(int (*csi_data_recv_callback)(void *buffer,
67816797
* \return WM_SUCCESS if successful
67826798
*/
67836799
int wlan_unregister_csi_user_callback(void);
6800+
6801+
6802+
#if CONFIG_CSI_AMI
6803+
/** This function set Ambient Motion Index configuration.
6804+
*
6805+
* \param[in] cfg: Ambient Motion Index configuration..
6806+
*/
6807+
void wlan_set_ami_cfg(wlan_csi_proc_cfg *cfg);
6808+
6809+
/** Use this API to start or stop caculate Ambient Motion Index.
6810+
*
6811+
* \param[in] start: start/stop
6812+
* 1: start
6813+
* 0: stop
6814+
*/
6815+
void wlan_start_stop_ami(uint8_t start);
6816+
#endif
67846817
#endif
67856818

67866819
#if (CONFIG_11K) || (CONFIG_11V) || (CONFIG_11R) || (CONFIG_ROAMING)
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* Copyright 2025 NXP
3+
*
4+
* SPDX-License-Identifier: BSD-3-Clause
5+
*
6+
*/
7+
8+
/*! \file event.h
9+
* \brief This file provides essential macro definitions and data structures for processing CSI event data.
10+
*/
11+
12+
#ifndef _LIB_CSI_EVENT_H_
13+
#define _LIB_CSI_EVENT_H_
14+
15+
#include <ctype.h>
16+
#include <stdlib.h>
17+
#include "wls_structure_defs.h"
18+
19+
#define PI_ALPHA_FACTOR 0.1f
20+
#define KALMAN_N0 0.2f
21+
#define KALMAN_P0 0.5f
22+
#define KALMAN_ALPHA 0.005f
23+
24+
typedef enum {
25+
AMI_FILTER_NOT_SET = 0, // Filter not set
26+
AMI_FILTER_SET, // Filter manually set via configuration
27+
AMI_FILTER_AUTO_SET, // Filter auto set from the first packet
28+
} ami_filter_set_status_t;
29+
30+
typedef enum {
31+
AMI_REF_UNINIT = 0, // AMI reference not initialized
32+
AMI_REF_INITIALIZED // AMI reference initialized
33+
} ami_reference_status_t;
34+
35+
typedef enum {
36+
AMI_STOP = 0, // AMI calculation stopped
37+
AMI_START // AMI calculation started
38+
} ami_start_status_t;
39+
40+
/** Structure for CSI config data*/
41+
typedef struct wls_csi_cfg
42+
{
43+
/** Channel number for FTM session*/
44+
t_u8 channel;
45+
/** Indicate whether CSI filter has been set */
46+
ami_filter_set_status_t csiFilterSet;
47+
/** Indicate whether start to caculate Ambient Motion Index.
48+
* AMI_STOP - stop. AMI_START - start */
49+
ami_start_status_t start;
50+
/** Indicates whether AMI reference has been initialized */
51+
ami_reference_status_t ami_reference_init;
52+
/**CSI processing config*/
53+
hal_wls_processing_input_params_t wls_processing_input;
54+
/**CSI filter parameters*/
55+
csi_filter_param_t gcsi_filter_param;
56+
} wls_csi_cfg_t, ami_cfg_t;
57+
58+
#endif /* _LIB_CSI_EVENT_H */
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Copyright 2025 NXP
3+
*
4+
* SPDX-License-Identifier: BSD-3-Clause
5+
*
6+
*/
7+
8+
/*! \file range_kalman.h
9+
* \brief This file contains Kalman filter for WLS range measurements.
10+
*/
11+
12+
#ifndef RANGE_KALMAN
13+
#define RANGE_KALMAN
14+
15+
#define RANGE_RUN_FLT
16+
#ifdef RANGE_RUN_FLT
17+
// range is in meters, range_rate in meters/second
18+
// time is in seconds
19+
typedef struct {
20+
// input
21+
unsigned long long time;
22+
float range_measurement;
23+
// state
24+
float last_range; // also output <--
25+
float last_range_rate;
26+
float R0_11, R0_22, R0_12;
27+
unsigned long long last_time;
28+
// model parameters
29+
float measurement_var;
30+
float drive_var;
31+
} range_kalman_state;
32+
33+
void range_kalman_init(range_kalman_state* in, float range, unsigned long long time, float range_drive_var, float range_measurement_var, float range_rate_init);
34+
#else
35+
// range format u16.8 in meters
36+
// time format is u64.0 in milliseconds
37+
typedef struct {
38+
// input
39+
unsigned long long time;
40+
unsigned int range_measurement;
41+
// state
42+
unsigned short last_range; // also output <--
43+
signed short last_range_rate;
44+
unsigned long long last_time;
45+
unsigned short R0_11, R0_22;
46+
signed int R0_12;
47+
// model parameters
48+
unsigned int measurement_var;
49+
unsigned int drive_var;
50+
} range_kalman_state;
51+
#endif
52+
53+
int range_kalman(range_kalman_state* in);
54+
55+
#endif
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Copyright 2025 NXP
3+
*
4+
* SPDX-License-Identifier: BSD-3-Clause
5+
*
6+
*/
7+
8+
/*! \file wls_api.h
9+
* \brief This file contains header file file for WLS processing fixed-point version API.
10+
*/
11+
12+
/************************************************************************
13+
* Header file for WLS processing fixed-point version API
14+
************************************************************************/
15+
#ifndef WLS_API_H
16+
#define WLS_API_H
17+
18+
#include "wls_structure_defs.h"
19+
#include "event.h"
20+
#ifdef DFW_CSI_PROC
21+
#include "dsp_cmd.h"
22+
#endif
23+
24+
int wls_process_csi(unsigned int *bufferMemory, unsigned int *fftInBuffer, hal_wls_packet_params_t *packetparams, hal_wls_processing_input_params_t *inputVals, unsigned int *resArray);
25+
int wls_unpack_csi(unsigned int *bufferMemory, unsigned int *outBuffer, hal_wls_packet_params_t *packetparams, hal_wls_processing_input_params_t *inputVals, unsigned int *totalpower, unsigned int *pktInfoPtr);
26+
int wls_calculate_toa(unsigned int *pktInfoPtr, int bufferSpacing, unsigned int *fftInBuffer, unsigned int *fftBuffer, unsigned int *totalpower, hal_wls_packet_params_t *packetparams, hal_wls_processing_input_params_t *inputVals);
27+
28+
void wls_intialize_reference(unsigned int *headerBuffer, unsigned int *pktInfoPtr, csi_filter_param_t *csi_filter_param_ptr, int bufferSpacing, unsigned int *fftInBuffer, float *fftRefBuffer);
29+
float wls_update_cross_corr_ami_calc(unsigned int *headerBuffer, unsigned int *pktInfoPtr, csi_filter_param_t *csi_filter_param_ptr, int bufferSpacing, unsigned int *fftInBuffer, float *fftRefBuffer, unsigned int *tempBuffer);
30+
#endif

0 commit comments

Comments
 (0)