

#include "typedef.h"


#include "cpri_csu.h"
#include "hw_cpri.h"
#include "cpri_driver.h"
#include "ucp_utility.h"
#include "ucp_printf.h"
#include "cpri_timer.h"
#include "HeaderRam.h"

#ifdef TEST_ENABLE
#include "cpri_test.h"
#endif

uint32_t HeaderTxtimes = 0;
volatile uint32_t gVendorFlag;
uint32_t HeaderTxAddr;
uint32_t *pHeaderTx = NULL;

void Cpri_Header_Tx(void)
{
	//uint32_t Txdata[48] ={0};//NS=8~19,each BF only bit[31:0]
	uint32_t XsIndex= 0;//Xs=0~3
	uint32_t CurrentHfnCnt =0;

	if(OTIC_MAP_FIGURE12 == gVendorFlag)
	{	
		CurrentHfnCnt = UCP_API_CPRI_GetTxHfnCnt();
		HeaderTxtimes++;
		
#ifdef TEST_ENABLE
		pHeaderTx = (uint32_t *)(HeaderTxDataAddr0 + ((HeaderTxtimes%2)*48*4));
#else
		if(pHeaderTx == NULL)
		{
			HeaderTxAddr = get_cpri_rru_msg_addr();
			pHeaderTx = (uint32_t *)HeaderTxAddr;
		}
#endif	

		if((CurrentHfnCnt ==HeaderTxHFN0) || ( CurrentHfnCnt == (HeaderTxHFN0-1)))
		{
			HeaderRam_ins_disable();

			//memcpy_ucp((uint32_t*)pHeaderTx,(uint32_t*)(HeaderTxDataAddr0 + ((HeaderTxtimes%2)*48*4)), 48*4);//NS=8~19

			for(XsIndex=0;XsIndex<4;XsIndex++)//按照RRU需求，控制字配置在NS=8~19传输，只使用控制字的[31:0],[127:32]保留不使用。而且只需要传164B，即41个基本帧
			{
				if(3 == XsIndex)//Xs=3,只需要5个基本帧
				{
					HeaderRam_Tx(8+64*XsIndex, 0,(*(pHeaderTx+XsIndex*12)),   0xF);//Reserved
					HeaderRam_Tx(9+64*XsIndex, 0,(*(pHeaderTx+1+XsIndex*12)), 0xF);//Reserved
					HeaderRam_Tx(10+64*XsIndex,0,(*(pHeaderTx+2+XsIndex*12)), 0xF);//Reserved
					HeaderRam_Tx(11+64*XsIndex,0,(*(pHeaderTx+3+XsIndex*12)), 0xF);//Reserved
					HeaderRam_Tx(12+64*XsIndex,0,(*(pHeaderTx+4+XsIndex*12)), 0xF);//Reserved
#ifdef TEST_ENABLE
					HeaderRam_Tx(13+64*XsIndex,0,(*(pHeaderTx+5+XsIndex*12)), 0xF);//Reserved
					HeaderRam_Tx(14+64*XsIndex,0,(*(pHeaderTx+6+XsIndex*12)), 0xF);//Reserved
					HeaderRam_Tx(15+64*XsIndex,0,(*(pHeaderTx+7+XsIndex*12)), 0xF);//Reserved
					HeaderRam_Tx(16+64*XsIndex,0,(*(pHeaderTx+8+XsIndex*12)), 0xF);//vendor
					HeaderRam_Tx(17+64*XsIndex,0,(*(pHeaderTx+9+XsIndex*12)), 0xF);//vendor
					HeaderRam_Tx(18+64*XsIndex,0,(*(pHeaderTx+10+XsIndex*12)),0xF);//vendor
					HeaderRam_Tx(19+64*XsIndex,0,(*(pHeaderTx+11+XsIndex*12)),0xF);//vendor
#endif
				}
				else
				{
					HeaderRam_Tx(8+64*XsIndex, 0,(*(pHeaderTx+XsIndex*12)),   0xF);//Reserved
					HeaderRam_Tx(9+64*XsIndex, 0,(*(pHeaderTx+1+XsIndex*12)), 0xF);//Reserved
					HeaderRam_Tx(10+64*XsIndex,0,(*(pHeaderTx+2+XsIndex*12)), 0xF);//Reserved
					HeaderRam_Tx(11+64*XsIndex,0,(*(pHeaderTx+3+XsIndex*12)), 0xF);//Reserved
					HeaderRam_Tx(12+64*XsIndex,0,(*(pHeaderTx+4+XsIndex*12)), 0xF);//Reserved
					HeaderRam_Tx(13+64*XsIndex,0,(*(pHeaderTx+5+XsIndex*12)), 0xF);//Reserved
					HeaderRam_Tx(14+64*XsIndex,0,(*(pHeaderTx+6+XsIndex*12)), 0xF);//Reserved
					HeaderRam_Tx(15+64*XsIndex,0,(*(pHeaderTx+7+XsIndex*12)), 0xF);//Reserved
					HeaderRam_Tx(16+64*XsIndex,0,(*(pHeaderTx+8+XsIndex*12)), 0xF);//vendor
					HeaderRam_Tx(17+64*XsIndex,0,(*(pHeaderTx+9+XsIndex*12)), 0xF);//vendor
					HeaderRam_Tx(18+64*XsIndex,0,(*(pHeaderTx+10+XsIndex*12)),0xF);//vendor
					HeaderRam_Tx(19+64*XsIndex,0,(*(pHeaderTx+11+XsIndex*12)),0xF);//vendor
				}			
			}

			HeaderRam_ins_enable();

			debug_write((DBG_DDR_IDX_CPRI_BASE+141), do_read_volatile(&AUX_CNT0));//0xb7e28234
		}
		debug_write((DBG_DDR_IDX_CPRI_BASE+144), CurrentHfnCnt);//0xb7e28240
	}

}

