130 lines
3.5 KiB
C
Executable File
130 lines
3.5 KiB
C
Executable File
/****************************************************************************
|
|
|
|
Copyright(c) 2019 by Aerospace C.Power (Chongqing) Microelectronics. ALL RIGHTS RESERVED.
|
|
|
|
This Information is proprietary to Aerospace C.Power (Chongqing) Microelectronics and MAY NOT
|
|
be copied by any method or incorporated into another program without
|
|
the express written consent of Aerospace C.Power. This Information or any portion
|
|
thereof remains the property of Aerospace C.Power. The Information contained herein
|
|
is believed to be accurate and Aerospace C.Power assumes no responsibility or
|
|
liability for its use in any way and conveys no license or title under
|
|
any patent or copyright and makes no representation or warranty that this
|
|
Information is free from patent or copyright infringement.
|
|
|
|
****************************************************************************/
|
|
#ifndef MAC_CHANNEL_H
|
|
#define MAC_CHANNEL_H
|
|
#include "iot_config.h"
|
|
#include "os_types.h"
|
|
#include "os_timer_api.h"
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
/* max rx count for stop channel scan */
|
|
#define MAX_BCN_RX_CNT 30
|
|
|
|
#define INV_SNR -15
|
|
|
|
/* if cur channel rx bcn snr big than it, stop scan */
|
|
#define MIN_SNR_STOP_SCAN 25
|
|
|
|
/* mac channel define */
|
|
#define MAC_CHANNEL_L_PE 0
|
|
#define MAC_CHANNEL_L_N 1
|
|
#define MAC_CHANNEL_N_PE 2
|
|
#define MAC_CHANNEL_MAX_NUM 3
|
|
|
|
#define CHANNL_CAL_AVG_SNR(AVG_SNR, CUR_SNR) ((AVG_SNR) - ((AVG_SNR) >> 2) + ((CUR_SNR) >> 2))
|
|
#define GET_BEST_CHANNEL(A_SNR, B_SNR, C_SNR) (((A_SNR) > (B_SNR)) ? \
|
|
(((A_SNR) > (C_SNR)) ? MAC_CHANNEL_L_PE : MAC_CHANNEL_N_PE) : \
|
|
(((B_SNR) > (C_SNR)) ? MAC_CHANNEL_L_N : MAC_CHANNEL_N_PE))
|
|
|
|
|
|
/* k48 channel select */
|
|
typedef struct _mac_channel_scan_ctxt {
|
|
/* cur rx channel */
|
|
uint8_t k48_cur_channel : 2,
|
|
/* all channel rx bcn cnt */
|
|
k48_channel_rx_count : 5,
|
|
/* channel is selected */
|
|
k48_channel_is_sel : 1;
|
|
/* 3 channel avg snr */
|
|
int8_t k48_channel_snr[MAC_CHANNEL_MAX_NUM];
|
|
/* channel scan timer */
|
|
timer_id_t scan_timer;
|
|
/* dwell time, unit second */
|
|
uint8_t dwell_time_s;
|
|
}mac_channel_scan_ctxt_t;
|
|
|
|
/*
|
|
* @brief iot_mac_k48sta_init_channelgpio
|
|
*/
|
|
void iot_mac_k48sta_init_channelgpio(void);
|
|
|
|
/*
|
|
* @brief iot_mac_k48cco_init_channelgpio
|
|
*/
|
|
void iot_mac_k48cco_init_channelgpio(void);
|
|
|
|
/*
|
|
* @brief iot_mac_k48sta_setchannel_gpio
|
|
*/
|
|
void iot_mac_k48sta_setchannel_gpio(uint8_t ch);
|
|
|
|
/*
|
|
* @brief iot_mac_chan_select
|
|
*
|
|
* @param phase: phase number.
|
|
*/
|
|
void iot_mac_chan_select(uint8_t phase);
|
|
|
|
/*
|
|
* @brief iot_mac_k48sta_switch_next_channel
|
|
*
|
|
* @param pdev: mac pdev pointer.
|
|
*/
|
|
void iot_mac_k48sta_switch_next_channel(void *pdev);
|
|
|
|
/*
|
|
* @brief iot_mac_k48sta_scan_channel_init
|
|
*
|
|
* @param pdev: mac pdev pointer.
|
|
*/
|
|
void iot_mac_k48sta_scan_channel_init(void *pdev);
|
|
|
|
/*
|
|
* @brief iot_mac_k48sta_scan_channel_start
|
|
*
|
|
* @param pdev: mac pdev pointer.
|
|
* @return 0:success, 1:fail
|
|
*/
|
|
uint32_t iot_mac_k48sta_scan_channel_start(void *pdev);
|
|
|
|
/*
|
|
* @brief iot_mac_k48sta_scan_channel_stop
|
|
*
|
|
* @param pdev: mac pdev pointer.
|
|
* @return 0:success, 1:fail
|
|
*/
|
|
uint32_t iot_mac_k48sta_scan_channel_stop(void *pdev);
|
|
|
|
/*
|
|
* @brief iot_mac_k48sta_channel_snr_cal
|
|
*
|
|
* @param pdev: mac pdev pointer.
|
|
* @param snr cur rx bcn snr
|
|
* @param ppm cur rx bcn ppm
|
|
* @return 0:success, 1:fail
|
|
*/
|
|
uint32_t iot_mac_k48sta_channel_snr_cal(void *pdev, int8_t snr, int8_t ppm);
|
|
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif
|
|
|