/* This file includes the initialization codes for FIR, IIR and FFT Accelerators */

#include "def21469.h"

.global _Init_FFT;

/* Declaring the external buffers needed for FFT Accelerator*/
.extern  FFT_IP_buff;
.extern  FFT_OP_buff;
.extern  FFT_CF_buff;


/*Adding the TCBs for FFT Accelerator*/

.section/dm seg_dmda;


	.var FFT_IP_TCB[6]={
				0,
				FFT_IP_buff,
				512,
				512,
				1,
				FFT_IP_buff
			};


	.var FFT_OP_TCB[6]={
				0,
				FFT_OP_buff,
				512,
				512,
				1,
				FFT_OP_buff
			};


	.var FFT_CF_TCB[6]={
				FFT_IP_TCB+5-0x80000,
				FFT_CF_buff,
				512,
				512,
				1,
				FFT_CF_buff
			};



/* Adding the FFT Initialization Code Now */

.section/pm seg_pmco;

_Init_FFT:

		//Mapping the FFT DMA interrupt
		ustat3=dm(PICR0);
		bit clr ustat3 P0I0|P0I1|P0I2|P0I3|P0I4;
		bit set ustat3 P0I0|P0I1|P0I3|P0I4;
		dm(PICR0)=ustat3;

		//Unamsking the FFT DMA interrupt
		bit set IMASK P0I;

		//Selecting the FFT Accelerator
		ustat1=dm(PMCTL1);
		bit clr ustat1 BIT_17|BIT_18;
		bit set ustat1 FFTACCSEL;
		dm(PMCTL1)=ustat1;

		//PMCTL1 effect latency
		nop;nop;nop;nop;

		//Clearing the FFTCTL registers
		ustat1=0;
		dm(FFTCTL2)=ustat1;

		ustat1=FFT_RST;
		dm(FFTCTL1)=ustat1;

		nop;nop;nop;nop;

		//Initializing the chain pointer registers
		ustat1=0x100000|(FFT_CF_TCB+5-0x80000);
		dm(CPIFFT)=ustat1;

		ustat1=FFT_OP_TCB+5-0x80000;
		dm(CPOFFT)=ustat1;

		//Configuring the FFTCTL2 Register
		ustat1=VDIMDIV16_16|FFT_LOG2VDIM_8;
		dm(FFTCTL2)=ustat1;

		//Configuring the FFTCTL1 Register
		ustat1=FFT_EN|FFT_START|FFT_DMAEN;
		dm(FFTCTL1)=ustat1;

		rts;


_Init_FFT.END: