176 lines
		
	
	
		
			5.5 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
		
		
			
		
	
	
			176 lines
		
	
	
		
			5.5 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_HW_TSFM_H_
							 | 
						||
| 
								 | 
							
								#define _MAC_HW_TSFM_H_
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#include "os_types.h"
							 | 
						||
| 
								 | 
							
								#include "plc_utils.h"
							 | 
						||
| 
								 | 
							
								#include "iot_config.h"
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#include "phy_bb.h"
							 | 
						||
| 
								 | 
							
								#include "mac_hw_tsfm_api.h"
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#ifdef __cplusplus
							 | 
						||
| 
								 | 
							
								extern "C" {
							 | 
						||
| 
								 | 
							
								#endif
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* encode timer period time. unit: 1us */
							 | 
						||
| 
								 | 
							
								#define MAC_HW_TSFM_ENCODE_TIMER_US         (500)
							 | 
						||
| 
								 | 
							
								/* encode signal tx time. unit: 1us */
							 | 
						||
| 
								 | 
							
								#define MAC_HW_TSFM_ENCODE_TX_US            (500)
							 | 
						||
| 
								 | 
							
								/* encode signal idle time. unit: 1us */
							 | 
						||
| 
								 | 
							
								#define MAC_HW_TSFM_ENCODE_IDLE_US          (500)
							 | 
						||
| 
								 | 
							
								/* tsfm data per bit encode time. unit: 1us */
							 | 
						||
| 
								 | 
							
								#define MAC_HW_TSFM_PER_BIT_DUR_US          (300 * 1000) /* 300ms */
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* check tsfm parameter valid */
							 | 
						||
| 
								 | 
							
								#if ((MAC_HW_TSFM_ENCODE_TX_US % MAC_HW_TSFM_ENCODE_TIMER_US) \
							 | 
						||
| 
								 | 
							
								    || (MAC_HW_TSFM_ENCODE_IDLE_US % MAC_HW_TSFM_ENCODE_TIMER_US) \
							 | 
						||
| 
								 | 
							
								    || (MAC_HW_TSFM_PER_BIT_DUR_US % MAC_HW_TSFM_ENCODE_TIMER_US) \
							 | 
						||
| 
								 | 
							
								    || (MAC_HW_TSFM_PER_BIT_DUR_US % (MAC_HW_TSFM_ENCODE_IDLE_US \
							 | 
						||
| 
								 | 
							
								        + MAC_HW_TSFM_ENCODE_TX_US)))
							 | 
						||
| 
								 | 
							
								#error "mac hw tsfm encode time slot config error"
							 | 
						||
| 
								 | 
							
								#endif
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* tsfm encode phy rate mode. see IOT_SUPPORT_RATE_XXX */
							 | 
						||
| 
								 | 
							
								#define MAC_HW_TSFM_ENCODE_RATE_MODE        (IOT_SUPPORT_RATE_XR)
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* per tone freq, unit: 1HZ
							 | 
						||
| 
								 | 
							
								 * SR mode, tone_freq = (1 / 1024) * 75MHZ = 73242HZ(about)
							 | 
						||
| 
								 | 
							
								 * QR mode, tone_freq = SR_freq / 4
							 | 
						||
| 
								 | 
							
								 * XR mode, tone_freq = SR_freq / 16
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								#if (MAC_HW_TSFM_ENCODE_RATE_MODE == IOT_SUPPORT_RATE_XR)
							 | 
						||
| 
								 | 
							
								/* freq = tone_num * (75M / 1024 / 16) \
							 | 
						||
| 
								 | 
							
								 *      = (tone_num * 75M) / (1 << 14)
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								#define mac_hw_tsfm_tonenum_to_freq(_tone_num)  \
							 | 
						||
| 
								 | 
							
								    ((uint32_t)(((uint64_t)(_tone_num) * 75 * 1000 * 1000) / (1 << 14)))
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* tone_num = freq / (75M / 1024 / 16)
							 | 
						||
| 
								 | 
							
								 *          = (freq * 1024 * 16) / 75M
							 | 
						||
| 
								 | 
							
								 *          = (freq * (1 << 14)) / 75M
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								#define mac_hw_tsfm_freq_to_tonenum(_freq)      \
							 | 
						||
| 
								 | 
							
								    iot_ceil(((uint64_t)(_freq) * (1 << 14)), ((uint64_t)75 * 1000 * 1000));
							 | 
						||
| 
								 | 
							
								#else
							 | 
						||
| 
								 | 
							
								#error "mac hw tsfm encode signal frequency error"
							 | 
						||
| 
								 | 
							
								#define mac_hw_tsfm_tonenum_to_freq(_tone_num)  \
							 | 
						||
| 
								 | 
							
								    do { \
							 | 
						||
| 
								 | 
							
								        (void)(_tone_num); \
							 | 
						||
| 
								 | 
							
								        IOT_ASSERT(0); \
							 | 
						||
| 
								 | 
							
								    } while(0)
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#define mac_hw_tsfm_freq_to_tonenum(_freq)      \
							 | 
						||
| 
								 | 
							
								    do { \
							 | 
						||
| 
								 | 
							
								        (void)(_freq); \
							 | 
						||
| 
								 | 
							
								        IOT_ASSERT(0); \
							 | 
						||
| 
								 | 
							
								    } while(0)
							 | 
						||
| 
								 | 
							
								#endif
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								typedef struct _mac_hw_tsfm_config {
							 | 
						||
| 
								 | 
							
								    /* hardware trnsmitter data bit length */
							 | 
						||
| 
								 | 
							
								    uint8_t bit_len;
							 | 
						||
| 
								 | 
							
								    /* reserved */
							 | 
						||
| 
								 | 
							
								    uint8_t rsvd0;
							 | 
						||
| 
								 | 
							
								    /* encode frequncy tone num */
							 | 
						||
| 
								 | 
							
								    uint16_t encode_tone_num;
							 | 
						||
| 
								 | 
							
								    /* hardware trnsmitter data */
							 | 
						||
| 
								 | 
							
								    uint8_t data[MAC_HW_TSFM_DATA_BYTE_MAX];
							 | 
						||
| 
								 | 
							
								} mac_hw_tsfm_config_t;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								typedef struct _mac_hw_tsfm_status {
							 | 
						||
| 
								 | 
							
								    /* current encode tsfm bit index */
							 | 
						||
| 
								 | 
							
								    uint8_t encode_idx;
							 | 
						||
| 
								 | 
							
								    /* 1: encode tx, 0: encode idle  */
							 | 
						||
| 
								 | 
							
								    uint8_t is_encode_tx; //TODO: fix to bit
							 | 
						||
| 
								 | 
							
								    /* reserved */
							 | 
						||
| 
								 | 
							
								    uint16_t rsvd0;
							 | 
						||
| 
								 | 
							
								    /* current encode timestamp, unit: 1us */
							 | 
						||
| 
								 | 
							
								    uint32_t encode_ts;
							 | 
						||
| 
								 | 
							
								    /* current tsfm bit encode start timestamp, unit: 1us */
							 | 
						||
| 
								 | 
							
								    uint32_t tsfm_bit_ts;
							 | 
						||
| 
								 | 
							
								} mac_hw_tsfm_status_t;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								typedef struct _mac_hw_tsfm_backup {
							 | 
						||
| 
								 | 
							
								    /* phy tx rate mode, see IOT_SUPPORT_RATE_XXX */
							 | 
						||
| 
								 | 
							
								    uint32_t tx_rate_mode_ovr   : 2,
							 | 
						||
| 
								 | 
							
								    /* ada eb reg config */
							 | 
						||
| 
								 | 
							
								        ada_eb                  : 1,
							 | 
						||
| 
								 | 
							
								    /* ada power on config */
							 | 
						||
| 
								 | 
							
								        ada_power_on            : 1,
							 | 
						||
| 
								 | 
							
								    /* phy ana pga gain. 0~3 */
							 | 
						||
| 
								 | 
							
								        ana_pga_gain            : 2,
							 | 
						||
| 
								 | 
							
								    /* bb tx power scale factor */
							 | 
						||
| 
								 | 
							
								        tx_pwr_scale_factor     : 5,
							 | 
						||
| 
								 | 
							
								    /* reserved */
							 | 
						||
| 
								 | 
							
								        rsvd0                   : 21;
							 | 
						||
| 
								 | 
							
								} mac_hw_tsfm_backup_t;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								typedef struct _mac_hw_tsfm_logger {
							 | 
						||
| 
								 | 
							
								    /* receive tx request count */
							 | 
						||
| 
								 | 
							
								    uint16_t tx_req_cnt;
							 | 
						||
| 
								 | 
							
								    /* execute tx request count */
							 | 
						||
| 
								 | 
							
								    uint16_t tx_complete_cnt;
							 | 
						||
| 
								 | 
							
								} mac_hw_tsfm_logger_t;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								typedef struct _mac_hw_tsfm_ctxt {
							 | 
						||
| 
								 | 
							
								    /* hardware transmitter timer id */
							 | 
						||
| 
								 | 
							
								    uint8_t timer_id;
							 | 
						||
| 
								 | 
							
								    /* reference pdev id */
							 | 
						||
| 
								 | 
							
								    uint8_t ref_pdev_id;
							 | 
						||
| 
								 | 
							
								    /* 0: normal mode, 1: tsfm mode */
							 | 
						||
| 
								 | 
							
								    uint16_t tsfm_mode          : 1,
							 | 
						||
| 
								 | 
							
								    /* reserved */
							 | 
						||
| 
								 | 
							
								        rsvd0                   : 15;
							 | 
						||
| 
								 | 
							
								    /* hardware transmitter config information */
							 | 
						||
| 
								 | 
							
								    mac_hw_tsfm_config_t        config;
							 | 
						||
| 
								 | 
							
								    /* hardware transmitter running status */
							 | 
						||
| 
								 | 
							
								    mac_hw_tsfm_status_t        status;
							 | 
						||
| 
								 | 
							
								    /* config backup */
							 | 
						||
| 
								 | 
							
								    mac_hw_tsfm_backup_t        backup;
							 | 
						||
| 
								 | 
							
								    /* hardware status flash log */
							 | 
						||
| 
								 | 
							
								    mac_hw_tsfm_logger_t        logger;
							 | 
						||
| 
								 | 
							
								} mac_hw_tsfm_ctxt_t;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/*
							 | 
						||
| 
								 | 
							
								 * @brief           mac hardware tsfm init
							 | 
						||
| 
								 | 
							
								 *
							 | 
						||
| 
								 | 
							
								 * @param fw_mode:  current firmware mode, see MM/FTM/MP_MODE
							 | 
						||
| 
								 | 
							
								 * @param pdev_id:  the pdev on which data will be init.
							 | 
						||
| 
								 | 
							
								 *
							 | 
						||
| 
								 | 
							
								 * @return          none
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								void mac_hw_tsfm_init(uint8_t fw_mode, uint8_t pdev_id);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/*
							 | 
						||
| 
								 | 
							
								 * @brief           mac hardware tsfm data
							 | 
						||
| 
								 | 
							
								 *
							 | 
						||
| 
								 | 
							
								 * @param pdev_id:  the pdev on which data will be sent.
							 | 
						||
| 
								 | 
							
								 * @param vdev_id:  the vdev on which data will be sent.
							 | 
						||
| 
								 | 
							
								 * @param tx_info:  tx config information
							 | 
						||
| 
								 | 
							
								 *
							 | 
						||
| 
								 | 
							
								 * @return          send duration time, unit: 1ms
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								uint32_t mac_hw_tsfm_send_internal(pdevid_t pdev_id, vdevid_t vdev_id,
							 | 
						||
| 
								 | 
							
								    mac_hw_tsfm_tx_info_t *tx_info);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#ifdef __cplusplus
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								#endif
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#endif
							 |