186 lines
		
	
	
		
			6.0 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
		
		
			
		
	
	
			186 lines
		
	
	
		
			6.0 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
| 
								 | 
							
								/****************************************************************************
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								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_RF_SCAN_H
							 | 
						||
| 
								 | 
							
								#define MAC_RF_SCAN_H
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#include "os_types.h"
							 | 
						||
| 
								 | 
							
								#include "os_timer_api.h"
							 | 
						||
| 
								 | 
							
								#include "iot_config.h"
							 | 
						||
| 
								 | 
							
								#include "mac_ppm_scan.h"
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#ifdef __cplusplus
							 | 
						||
| 
								 | 
							
								extern "C" {
							 | 
						||
| 
								 | 
							
								#endif
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* define rf scan timer unit 500ms */
							 | 
						||
| 
								 | 
							
								#define MAC_RF_SCAN_TIMER_UNIT                   (500)
							 | 
						||
| 
								 | 
							
								/* define rf scan default dwell uint MAC_RF_SCAN_TIMER_UNIT, 15s */
							 | 
						||
| 
								 | 
							
								#define MAC_RF_SCAN_DWELL_TIME                   (30)
							 | 
						||
| 
								 | 
							
								/* define rf scan default dwell uint MAC_RF_SCAN_TIMER_UNIT, 5s */
							 | 
						||
| 
								 | 
							
								#define MAC_RF_SCAN_MIN_TIME                     (10)
							 | 
						||
| 
								 | 
							
								/* define rf scan default dwell uint MAC_RF_SCAN_TIMER_UNIT, 20s */
							 | 
						||
| 
								 | 
							
								#define MAC_RF_SCAN_FIRST_DWELL_TIME             (40)
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* define scan option cahnnel table max */
							 | 
						||
| 
								 | 
							
								#define MAC_RF_SCAN_OP_CHN_MAX                   (104)
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* scan option channel */
							 | 
						||
| 
								 | 
							
								typedef struct _mac_rf_scan_option_channel {
							 | 
						||
| 
								 | 
							
								    /* scan option id */
							 | 
						||
| 
								 | 
							
								    uint8_t option_id;
							 | 
						||
| 
								 | 
							
								    /* scan channel id */
							 | 
						||
| 
								 | 
							
								    uint8_t channel_id;
							 | 
						||
| 
								 | 
							
								    /* option and channel min time, uint MAC_RF_SCAN_TIMER_UNIT */
							 | 
						||
| 
								 | 
							
								    uint8_t min_time;
							 | 
						||
| 
								 | 
							
								    /* option and channel dwell time, uint MAC_RF_SCAN_TIMER_UNIT */
							 | 
						||
| 
								 | 
							
								    uint8_t dwell_time;
							 | 
						||
| 
								 | 
							
								} mac_rf_scan_op_chn_t;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* channel table ctxt */
							 | 
						||
| 
								 | 
							
								typedef struct _mac_rf_scan_op_chn_ctxt {
							 | 
						||
| 
								 | 
							
								    /* the point of scan option channel table */
							 | 
						||
| 
								 | 
							
								    mac_rf_scan_op_chn_t *rf_scan_op_chn_tbl;
							 | 
						||
| 
								 | 
							
								} mac_rf_scan_op_chn_ctxt_t;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* this is per rf pdev, for channel scan */
							 | 
						||
| 
								 | 
							
								typedef struct _mac_rf_scan_ctxt {
							 | 
						||
| 
								 | 
							
								    /* which option is on */
							 | 
						||
| 
								 | 
							
								    uint8_t option_id;
							 | 
						||
| 
								 | 
							
								    /* which channel is on */
							 | 
						||
| 
								 | 
							
								    uint8_t channel_id;
							 | 
						||
| 
								 | 
							
								    /* flags */
							 | 
						||
| 
								 | 
							
								    uint16_t
							 | 
						||
| 
								 | 
							
								        /* means option/channel selected by upper layer */
							 | 
						||
| 
								 | 
							
								        channel_selected : 1,
							 | 
						||
| 
								 | 
							
								        /* flag to mark if current option/channel rx packet is valid */
							 | 
						||
| 
								 | 
							
								        is_valid_packet :  1,
							 | 
						||
| 
								 | 
							
								        resv            :  14;
							 | 
						||
| 
								 | 
							
								    /* scan table cnt */
							 | 
						||
| 
								 | 
							
								    uint8_t scan_cnt;
							 | 
						||
| 
								 | 
							
								    /* current scan idx */
							 | 
						||
| 
								 | 
							
								    uint8_t scan_idx;
							 | 
						||
| 
								 | 
							
								    /* ppm scan timer */
							 | 
						||
| 
								 | 
							
								    timer_id_t rf_scan_timer;
							 | 
						||
| 
								 | 
							
								    /* mac rf scan option channel ctxt */
							 | 
						||
| 
								 | 
							
								    mac_rf_scan_op_chn_ctxt_t rf_scan_op_chn_ctxt;
							 | 
						||
| 
								 | 
							
								    uint32_t phr_with_pld_cnt;
							 | 
						||
| 
								 | 
							
								    uint32_t phr_witchout_pld_cnt;
							 | 
						||
| 
								 | 
							
								    /* record rf timer start ms */
							 | 
						||
| 
								 | 
							
								    uint32_t timer_start_ms;
							 | 
						||
| 
								 | 
							
								} mac_rf_scan_ctxt_t;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/*
							 | 
						||
| 
								 | 
							
								 * @breif mac_rf_scan_set_scan_tbl()        - set rf scan table.
							 | 
						||
| 
								 | 
							
								 * @param tbl_size                          - table size.
							 | 
						||
| 
								 | 
							
								 * @param rf_scan_tbl                       - the point to set scan table.
							 | 
						||
| 
								 | 
							
								 * @return void                             - void.
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								void mac_rf_scan_set_scan_tbl(uint8_t tbl_size, uint8_t *rf_scan_tbl);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/**
							 | 
						||
| 
								 | 
							
								 *@brief mac_rf_scan_start  start mac rf scan process
							 | 
						||
| 
								 | 
							
								 *
							 | 
						||
| 
								 | 
							
								 *@exception                [none.]
							 | 
						||
| 
								 | 
							
								 *@return                   [none.]
							 | 
						||
| 
								 | 
							
								*/
							 | 
						||
| 
								 | 
							
								uint32_t mac_rf_scan_start();
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/**
							 | 
						||
| 
								 | 
							
								 *@brief mac_rf_scan_stop
							 | 
						||
| 
								 | 
							
								 *
							 | 
						||
| 
								 | 
							
								 * stop mac scan process, usually found a candidate
							 | 
						||
| 
								 | 
							
								 *
							 | 
						||
| 
								 | 
							
								 *@exception                [none.]
							 | 
						||
| 
								 | 
							
								 *@return                   [none.]
							 | 
						||
| 
								 | 
							
								*/
							 | 
						||
| 
								 | 
							
								uint32_t mac_rf_scan_stop();
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/**
							 | 
						||
| 
								 | 
							
								 * @brief mac_scan_set_channel_selected
							 | 
						||
| 
								 | 
							
								 * @param is_sel            [1: selected done; 0: not selected, need scan]
							 | 
						||
| 
								 | 
							
								 * @return                  [ERR_OK or else fail]
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								void mac_rf_scan_set_channel_selected(uint32_t is_sel);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/**
							 | 
						||
| 
								 | 
							
								 * @brief mac_rf_scan_get_channel_selected
							 | 
						||
| 
								 | 
							
								 * @return                  [1: selected done; 0: not selected, need scan]
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								uint32_t mac_rf_scan_get_channel_selected();
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/**
							 | 
						||
| 
								 | 
							
								 *@brief mac_rf_scan_next_target jump to next target option/channel section
							 | 
						||
| 
								 | 
							
								 *
							 | 
						||
| 
								 | 
							
								 *@param arg                     [rf pdev context]
							 | 
						||
| 
								 | 
							
								 *@exception                     [none.]
							 | 
						||
| 
								 | 
							
								 *@return                        [none.]
							 | 
						||
| 
								 | 
							
								*/
							 | 
						||
| 
								 | 
							
								uint32_t mac_rf_scan_next_target(void *arg);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/**
							 | 
						||
| 
								 | 
							
								 *@brief mac_rf_scan_init       init the rf scan context in pdev
							 | 
						||
| 
								 | 
							
								 *
							 | 
						||
| 
								 | 
							
								 *@param pdev_in                [rf pdev pointer]
							 | 
						||
| 
								 | 
							
								 *@exception                    [none.]
							 | 
						||
| 
								 | 
							
								 *@return                       [none.]
							 | 
						||
| 
								 | 
							
								*/
							 | 
						||
| 
								 | 
							
								void mac_rf_scan_init(void *pdev_in);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/**
							 | 
						||
| 
								 | 
							
								 *@brief mac_rf_scan_update_rx_status   update rx status
							 | 
						||
| 
								 | 
							
								 *
							 | 
						||
| 
								 | 
							
								 *@param vdev                   [mac vdev pointer]
							 | 
						||
| 
								 | 
							
								 *@param scan                   [point to rf scan context]
							 | 
						||
| 
								 | 
							
								 *@param nid                    [the nid for the packet to be processed]
							 | 
						||
| 
								 | 
							
								 *@param rx_channel             [the rx channel for the packet to be processed]
							 | 
						||
| 
								 | 
							
								 *@exception                    [none.]
							 | 
						||
| 
								 | 
							
								 *@return                       [none.]
							 | 
						||
| 
								 | 
							
								*/
							 | 
						||
| 
								 | 
							
								void mac_rf_scan_update_rx_status(void *vdev_in, mac_rf_scan_ctxt_t *scan,
							 | 
						||
| 
								 | 
							
								    uint32_t nid, uint8_t rx_channel);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/**
							 | 
						||
| 
								 | 
							
								 *@brief mac_rf_ntb_ppm_sync    mac rf sync ppm
							 | 
						||
| 
								 | 
							
								 *
							 | 
						||
| 
								 | 
							
								 *@param rf_vdev                [mac rf vdev pointer]
							 | 
						||
| 
								 | 
							
								 *@param remote_ts              [network timestamp]
							 | 
						||
| 
								 | 
							
								 *@param local_ts               [local ts]
							 | 
						||
| 
								 | 
							
								 *@param local_ntb              [local ntb]
							 | 
						||
| 
								 | 
							
								 *@param bcn_period_ms          [bcn period]
							 | 
						||
| 
								 | 
							
								 *@param ppm_err_record         [ppm_err_record]
							 | 
						||
| 
								 | 
							
								 *@param rfppm                  [rf ppm from interface]
							 | 
						||
| 
								 | 
							
								 *@exception                    [none.]
							 | 
						||
| 
								 | 
							
								 *@return uint32_t              [0.]
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								uint32_t mac_rf_ntb_ppm_sync(void *rf_vdev,
							 | 
						||
| 
								 | 
							
								    uint32_t remote_ts, uint32_t local_ts, uint32_t local_ntb,
							 | 
						||
| 
								 | 
							
								    uint32_t bcn_period_ms, int16_t *ppm_err_record, int16_t rfppm);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/**
							 | 
						||
| 
								 | 
							
								 *@brief mac_rf_ppm_init        mac rf ppm context
							 | 
						||
| 
								 | 
							
								 *
							 | 
						||
| 
								 | 
							
								 *@param rf_vdev                [mac rf vdev pointer]
							 | 
						||
| 
								 | 
							
								 *@param ppm                    [ppm value, unit: 1/64]
							 | 
						||
| 
								 | 
							
								 *@return                       [none]
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								void mac_rf_ppm_init(void *rf_vdev, int16_t ppm);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#ifdef __cplusplus
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								#endif
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#endif // !MAC_RF_SCAN_H
							 |