#include "rfm0_mtimer.h"
#include "typedef.h"
#include "phy_para.h"
#include "ucp_printf.h"
#include "ucp_utility.h"
#include "phy_para.h"
#ifdef DISTRIBUTED_BS
#include "rfm0_cpri_timer.h"
#include "rfm0_ecpri_timer.h"
#endif
#ifdef INTEGRATED_BS
#include "rfm0_jesd_timer.h"
#endif

stPhyCellPara* pPhyCellPara = (stPhyCellPara*)PHY_CELL_ADDR;
extern stPhyScsPara*	phyPara;
extern uint32_t			gScsId;
extern uint32_t			gMtimerId;
extern stSfnPara		gCellSfnPara[2];

void rfm0_mtimer_int_init(void)
{
#ifdef DISTRIBUTED_BS
    if (MTIMER_CPRI_ID == gMtimerId)
    {
        set_cpri_timer_rfm0_int();
    }
    else
    {
        set_ecpri_timer_rfm0_int();
    }
#endif
#ifdef INTEGRATED_BS
    set_jesd_timer_rfm0_int(gMtimerId);
#endif
}

void phy_cell_para_init(int32_t nScsId)
{
	memset_ext((void*)pPhyCellPara, 0, sizeof(stPhyCellPara));
	__ucps2_synch(f_SMW);
	
	memset(&gCellSfnPara[gMtimerId], 0, sizeof(stSfnPara));
	gScsId = nScsId;
	gCellSfnPara[gMtimerId].scsId = gScsId;
	gCellSfnPara[gMtimerId].slotPeriod = do_read_volatile_short(&(phyPara[gScsId].slotPeriod));		// 500; // 
	gCellSfnPara[gMtimerId].tddSlotNum = do_read_volatile_short(&(phyPara[gScsId].slotNumOfTdd));	// 10;  // 
	gCellSfnPara[gMtimerId].slotMaxNum = do_read_volatile_short(&(phyPara[gScsId].slotNumOfSfn));	// 20;  // 
	__ucps2_synch(f_SMR);
	gCellSfnPara[gMtimerId].txSlotNum = gCellSfnPara[gMtimerId].slotMaxNum - 1;
	gCellSfnPara[gMtimerId].txSfnNum = 1023;
	gCellSfnPara[gMtimerId].rxSlotNum = gCellSfnPara[gMtimerId].slotMaxNum - 1;
	gCellSfnPara[gMtimerId].rxSfnNum = 1023;
}

