215 lines
		
	
	
		
			6.8 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
		
		
			
		
	
	
			215 lines
		
	
	
		
			6.8 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_SCHED_HW_H
							 | 
						||
| 
								 | 
							
								#define MAC_SCHED_HW_H
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* os shim includes */
							 | 
						||
| 
								 | 
							
								#include "os_types.h"
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* mac module internal includes */
							 | 
						||
| 
								 | 
							
								#include "mac_vdev.h"
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* plc public api includes */
							 | 
						||
| 
								 | 
							
								#include "plc_fr.h"
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#ifdef __cplusplus
							 | 
						||
| 
								 | 
							
								extern "C" {
							 | 
						||
| 
								 | 
							
								#endif
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#if HW_PLATFORM == HW_PLATFORM_SIMU
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* convert ntb to ms. in simulator, the ntb unit is 1ms */
							 | 
						||
| 
								 | 
							
								#define MAC_NTB_TO_MS(ntb)          (ntb)
							 | 
						||
| 
								 | 
							
								/* convert ms to ntb. in simulator, the ntb uint is 1ms */
							 | 
						||
| 
								 | 
							
								#define MAC_MS_TO_NTB(ms)           (ms)
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* alead alert time before the end of current beacon period. unit is 1ms. */
							 | 
						||
| 
								 | 
							
								#define MAC_BP_AHEAD_ALERT_DUR      70
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* ahead time before next beacon period while config the next bp scheduler.
							 | 
						||
| 
								 | 
							
								 * unit is 1ms.
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								#define MAC_BP_AHEAD_NEXT_BP_DUR    20
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* golden gap value suggested by HW team. this value will assist HW to sync
							 | 
						||
| 
								 | 
							
								 * up NTB with remote device. This value shouldn't be changed unless required
							 | 
						||
| 
								 | 
							
								 * by HW team. the unit is 1 NTB.
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								#define MAC_SCHED_GOLDEN_GAP        13541
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#else /* HW_PLATFORM */
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* convert ntb to ms. in HW, the ntb clock freq is 25 mhz. */
							 | 
						||
| 
								 | 
							
								#define MAC_NTB_TO_MS(ntb)          ((ntb) / (25 * 1000))
							 | 
						||
| 
								 | 
							
								/* convert ms to ntb. in HW, the ntb clock freq is 25 mhz. */
							 | 
						||
| 
								 | 
							
								#define MAC_MS_TO_NTB(ms)           ((ms) * (25 * 1000))
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* ahead alert time before the end of current beacon period. unit is 1ms. */
							 | 
						||
| 
								 | 
							
								#if !IOT_HTBUS_EN
							 | 
						||
| 
								 | 
							
								#define MAC_BP_AHEAD_ALERT_DUR      70
							 | 
						||
| 
								 | 
							
								#else
							 | 
						||
| 
								 | 
							
								#define MAC_BP_AHEAD_ALERT_DUR      5
							 | 
						||
| 
								 | 
							
								#endif
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* ahead time before next beacon period while config the next bp scheduler.
							 | 
						||
| 
								 | 
							
								 * unit is 1ms.
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								#if !IOT_HTBUS_EN
							 | 
						||
| 
								 | 
							
								#define MAC_BP_AHEAD_NEXT_BP_DUR    20
							 | 
						||
| 
								 | 
							
								#else
							 | 
						||
| 
								 | 
							
								#define MAC_BP_AHEAD_NEXT_BP_DUR    5
							 | 
						||
| 
								 | 
							
								#endif
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#if DBG_NTB_SYNC
							 | 
						||
| 
								 | 
							
								/* TODO: for debug NTB has shift about 10us */
							 | 
						||
| 
								 | 
							
								#define MAC_SYNC_SHIFT_NTB          125
							 | 
						||
| 
								 | 
							
								#else
							 | 
						||
| 
								 | 
							
								#define MAC_SYNC_SHIFT_NTB          0
							 | 
						||
| 
								 | 
							
								#endif
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* SW set tx delay ntb time duration between tx start and first sample on power
							 | 
						||
| 
								 | 
							
								 * line
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								#define MAC_SW_TX_BTS_DLY_NTB       (895)
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* HW set tx delay ntb time duration between tx start and first sample on power
							 | 
						||
| 
								 | 
							
								 * line
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								#define MAC_HW_TX_BTS_DLY_NTB       (960)
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* golden gap value suggested by HW team. this value will assist HW to sync
							 | 
						||
| 
								 | 
							
								 * up NTB with remote device. This value shouldn't be changed unless required
							 | 
						||
| 
								 | 
							
								 * by HW team. the unit is 1 NTB.
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								#define MAC_SCHED_GOLDEN_GAP        ((13541) + MAC_SYNC_SHIFT_NTB)
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#endif /* HW_PLATFORM */
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/*
							 | 
						||
| 
								 | 
							
								 * @brief mac_sched_enable_hw_ntb_sync() - config HW to enable/disable automatic
							 | 
						||
| 
								 | 
							
								 * @brief                                  HW NTB sync feature.
							 | 
						||
| 
								 | 
							
								 *
							 | 
						||
| 
								 | 
							
								 * @param vdev:         pointer to mac vdev
							 | 
						||
| 
								 | 
							
								 * @param enable:       1 - enable. 0 - disable.
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								void mac_sched_enable_hw_ntb_sync(mac_vdev_t *vdev, uint8_t enable);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* mac_sched_sync_ntb() - config HW to sync up local NTB with the NTB
							 | 
						||
| 
								 | 
							
								 *                        of preferred network.
							 | 
						||
| 
								 | 
							
								 * @vdev:       pointer to mac vdev
							 | 
						||
| 
								 | 
							
								 * @golden_gap: the time consumed from remote tx to local rx.
							 | 
						||
| 
								 | 
							
								 * @ntb_delta:  the delta between local NTB and preferred network NTB
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								void mac_sched_sync_ntb(mac_vdev_t *vdev, uint16_t golden_gap,
							 | 
						||
| 
								 | 
							
								    int32_t ntb_delta);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* mac_sched_get_ntb() - get local NTB
							 | 
						||
| 
								 | 
							
								 * @vdev:       pointer to mac vdev
							 | 
						||
| 
								 | 
							
								 *
							 | 
						||
| 
								 | 
							
								 * return:
							 | 
						||
| 
								 | 
							
								 *      local NTB
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								uint32_t mac_sched_get_ntb(mac_vdev_t *vdev);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* mac_sched_get_ntb64() - get local NTB 64bit version
							 | 
						||
| 
								 | 
							
								 * @vdev:       pointer to mac vdev
							 | 
						||
| 
								 | 
							
								 *
							 | 
						||
| 
								 | 
							
								 * return:
							 | 
						||
| 
								 | 
							
								 *      local NTB 64bit version
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								uint64_t mac_sched_get_ntb64(mac_vdev_t *vdev);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* mac_sched_set_bp_ahead_alert() - config beacon period ahead alert interrupt
							 | 
						||
| 
								 | 
							
								 *                                  to be fired right before ahead time.
							 | 
						||
| 
								 | 
							
								 * @vdev:       pointer to mac vdev
							 | 
						||
| 
								 | 
							
								 * @ahead:      ahead time. unit is 1 ms.
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								void mac_sched_set_bp_ahead_alert(mac_vdev_t *vdev, uint16_t ahead);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* mac_sched_set_recursive_mode() - set HW to work in either recursive mode or
							 | 
						||
| 
								 | 
							
								 *                                  not. if recursive mode enabled, HW will
							 | 
						||
| 
								 | 
							
								 *                                  re-run the command list in PING unless
							 | 
						||
| 
								 | 
							
								 *                                  PONG is valid or SW stop the shceduler.
							 | 
						||
| 
								 | 
							
								 * @vdev:       pointer to mac vdev
							 | 
						||
| 
								 | 
							
								 * @enable:     0 to disable and 1 to enable recursive mode.
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								void mac_sched_set_recursive_mode(mac_vdev_t *vdev, uint8_t enable);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* mac_sched_set_bp_start_ntb() - config start ntb of next beacon period
							 | 
						||
| 
								 | 
							
								 * @vdev:       pointer to mac vdev
							 | 
						||
| 
								 | 
							
								 * @start_ntb:  start ntb of next beacon period
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								void mac_sched_set_bp_start_ntb(mac_vdev_t *vdev, uint32_t start_ntb);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* mac_sched_set_bp_dur() - config duration of next beacon period
							 | 
						||
| 
								 | 
							
								 * @vdev:       pointer to mac vdev
							 | 
						||
| 
								 | 
							
								 * @bp:         duration of next beacon period
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								void mac_sched_set_bp_dur(mac_vdev_t *vdev, uint16_t bp);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* mac_sched_set_bp_cmd_list() - config command list of next beacon period
							 | 
						||
| 
								 | 
							
								 * @vdev:       pointer to mac vdev
							 | 
						||
| 
								 | 
							
								 * @cmd:        pointer to the array of the commands
							 | 
						||
| 
								 | 
							
								 * @cnt:        number of cmd in the array
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								void mac_sched_set_bp_cmd_list(mac_vdev_t *vdev, hw_sched_cmd_t *cmd,
							 | 
						||
| 
								 | 
							
								    uint16_t cnt);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* mac_sched_get_cmd_list_cnt() - get number of pending command list include
							 | 
						||
| 
								 | 
							
								 *                                the command list being executed.
							 | 
						||
| 
								 | 
							
								 * @vdev:       pointer to mac vdev
							 | 
						||
| 
								 | 
							
								 *
							 | 
						||
| 
								 | 
							
								 * return:
							 | 
						||
| 
								 | 
							
								 *      number of pending command list
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								uint8_t mac_sched_get_cmd_list_cnt(mac_vdev_t *vdev);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* mac_sched_trigger_bp() - trigger HW to load the configuration of next
							 | 
						||
| 
								 | 
							
								 *                          beacon period
							 | 
						||
| 
								 | 
							
								 * @vdev:       pointer to mac vdev
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								void mac_sched_trigger_bp(mac_vdev_t *vdev);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* mac_sched_enable_bp() - enable or disable HW scheduler
							 | 
						||
| 
								 | 
							
								 * @vdev:       pointer to mac vdev
							 | 
						||
| 
								 | 
							
								 * @enable:     0 for disable and 1 for enable
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								void mac_sched_enable_bp(mac_vdev_t *vdev, uint8_t enable);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* mac_sched_get_lts() - get local free run timer tick
							 | 
						||
| 
								 | 
							
								 *
							 | 
						||
| 
								 | 
							
								 * return:
							 | 
						||
| 
								 | 
							
								 *      local free run timer tick, 0.04us unit
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								uint32_t mac_sched_get_lts();
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* mac_sched_get_bp_start_ntb() -get bp start ntb
							 | 
						||
| 
								 | 
							
								 * return:                      -start ntb
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								uint32_t mac_sched_get_bp_start_ntb();
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* mac_sched_get_bp_dur()       -get beacon period
							 | 
						||
| 
								 | 
							
								 * return:                      -bc period
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								uint32_t mac_sched_get_bp_dur();
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#ifdef __cplusplus
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								#endif
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#endif /* MAC_SCHED_HW_H */
							 |