#include <Equalizer_1port.h>
#include "ucps2.h"
#include "ucpm2.h"


void EQ21Part1(int* ConfigBaseAddr,int NRE,int Nsymbol,int InputAddr0,int InputAddr1,int InputAddr2,int OutputAddr0,int OutputAddr1,int OutputAddr2,int OutputAddr3){

	int *addr_move = ConfigBaseAddr;
	//data cycle
	int cycle=((NRE+15)>>4)*Nsymbol;
    addr_move[0] = cycle;
    int KBNum = (((NRE + 15) >> 4) << 6)* (Nsymbol - 1) + NRE*4;
    int SymbolStep = ((NRE+15)>>4) << 6;//NRE*4;
    int KI = (NRE+15)>>4;

    //intput h
	addr_move[0+16] = InputAddr0;
	addr_move[1+16] = InputAddr0;
	addr_move[2+16] = InputAddr0;
	addr_move[4+16] = NRE * 4;
	addr_move[6+16] = NRE * 4 * 2;
	addr_move[9+16] = (KI<<16)+KI;
	addr_move[10+16] = (Nsymbol<<16)+Nsymbol;



	//input noise
	addr_move[0+16*2] = InputAddr1;
	addr_move[1+16*2] = InputAddr1;
	addr_move[8+16*2] = (KI<<16)+KI;

	//intput y
	addr_move[0+16*3] = InputAddr2;
	addr_move[1+16*3] = InputAddr2;
	addr_move[2+16*3] = InputAddr2;
	addr_move[4+16*3] = NRE<<2;
	addr_move[6+16*3] = NRE*4*2;
	addr_move[9+16*3] = (KI<<16)+KI;
	addr_move[10+16*3] = (Nsymbol<<16)+Nsymbol;

	//output invHH'
	addr_move[0+16*4] = OutputAddr1;
	addr_move[1+16*4] = OutputAddr1;
	addr_move[5+16*4] = NRE<<2;
	addr_move[8+16*4] = (KI<<16)+KI;
	addr_move[9+16*4] = (Nsymbol<<16)+Nsymbol;
	addr_move[12+16*4] = KBNum;

	//output MF
	addr_move[0+16*5] = OutputAddr2;
	addr_move[1+16*5] = OutputAddr2;
	addr_move[5+16*5] = NRE<<2;
	addr_move[8+16*5] = (KI<<16)+KI;
	addr_move[9+16*5] = (Nsymbol<<16)+Nsymbol;
	addr_move[12+16*5] = KBNum;

	//output Qtemp QMF
	addr_move[0+16*6] = OutputAddr3;
	addr_move[1+16*6] = OutputAddr3;
	addr_move[2+16*6] = OutputAddr3;
	addr_move[4+16*6] = SymbolStep;
	addr_move[6+16*6] = SymbolStep * 2;
	addr_move[9+16*6] = (KI<<16)+KI;
	addr_move[10+16*6] = (Nsymbol<<16)+Nsymbol;

	//output H'H>>13
	addr_move[0+16*7] = OutputAddr0;
	addr_move[1+16*7] = OutputAddr0;
	addr_move[5+16*7] = NRE<<2;
	addr_move[8+16*7] = (KI<<16)+KI;
	addr_move[9+16*7] = (Nsymbol<<16)+Nsymbol;
	addr_move[12+16*7] = KBNum;

	return;
}


void EQ1Part2(int* ConfigBaseAddr,int NRE,int Nsymbol,int InputAddr0,int InputAddr1,int InputAddr2,int InputAddr3,int OutputAddr0,int OutputAddr1){

	int *addr_move = ConfigBaseAddr;
	//data cycle
	int cycle=((NRE+15)>>4)*Nsymbol;
    addr_move[0] = cycle;
    int KBNum_EQ = (((NRE + 15) >> 4) << 4)*4 * (Nsymbol - 1) + NRE*4;
    int KBNum_MMSE = (((NRE + 15) >> 4) << 4)*2 * (Nsymbol - 1) + NRE*2;
    int SymbolStep = ((NRE+15)>>4) << 6;//NRE*4;
    int KI = (NRE+15)>>4;

    //input invh'h
	addr_move[0+16] = InputAddr1;
	addr_move[1+16] = InputAddr1;
	addr_move[5+16] = NRE<<2;
	addr_move[8+16] = (KI<<16)+KI;
	addr_move[9+16] = (Nsymbol<<16)+Nsymbol;
	//addr_move[12+16] = KBNum;

	//input MF
	addr_move[0+16*2] = InputAddr2;
	addr_move[1+16*2] = InputAddr2;
	addr_move[5+16*2] = NRE<<2;
	addr_move[8+16*2] = (KI<<16)+KI;
	addr_move[9+16*2] = (Nsymbol<<16)+Nsymbol;
	//addr_move[12+16*2] = KBNum;

	//input Qtemp0 QMF
	addr_move[0+16*3] = InputAddr3;
	addr_move[1+16*3] = InputAddr3;
	addr_move[2+16*3] = InputAddr3;
	addr_move[4+16*3] = SymbolStep;
	addr_move[6+16*3] = SymbolStep * 2;
	addr_move[9+16*3] = (KI<<16)+KI;
	addr_move[10+16*3] = (Nsymbol<<16)+Nsymbol;
	//addr_move[12+16*3] = KBNum;

	//input H'H >> 13
	addr_move[0+16*4] = InputAddr0;
	addr_move[1+16*4] = InputAddr0;
	addr_move[5+16*4] = NRE<<2;
	addr_move[8+16*4] = (KI<<16)+KI;
	addr_move[9+16*4] = (Nsymbol<<16)+Nsymbol;
	//addr_move[12+16*4] = KBNum;

	//out EQ
	addr_move[0+16*5] = OutputAddr0;
	addr_move[1+16*5] = OutputAddr0;
	addr_move[5+16*5] = NRE<<2;
	addr_move[8+16*5] = (KI<<16)+KI;
	addr_move[9+16*5] = (Nsymbol<<16)+Nsymbol;
	addr_move[12+16*5] = KBNum_EQ;

	//output gainMMSE
	addr_move[0+16*6] = OutputAddr1;
	addr_move[1+16*6] = OutputAddr1;
	addr_move[5+16*6] = NRE*2;
	addr_move[8+16*6] = (KI<<16)+KI;
	addr_move[9+16*6] = (Nsymbol<<16)+Nsymbol;
	addr_move[12+16*6] = KBNum_MMSE;


	return;

}


