예제 #1
0
void init_dma(void)
{
     HWI_Attrs hwiAttrs;
     Uns dmaTxSynEvt, dmaRxSynEvt;
     Uint32 dmaTxDest, dmaRxSrc;
     LgUns tempAdd;
     DMA_Config dmaTxCfg, dmaRxCfg;

     DMA_FSET(DMAGCR,FREE,0); 
     DMA_getConfig(hDmaTx, &dmaTxCfg); 
     dmaTxDest = MCBSP_ADDR(DXR21) << 1;
     /* Setup Tx Side addresses based on MCBSP port */
     dmaTxCfg.dmacdsal = (DMA_AdrPtr)(dmaTxDest & 0xFFFF);
     dmaTxCfg.dmacdsau = ((dmaTxDest >> 15) & 0xFFFF);
     tempAdd = (LgUns)(&txBuffer[0]) << 1; /* byte address */
     dmaTxCfg.dmacssal = (DMA_AdrPtr)(tempAdd & 0xFFFF);
     dmaTxCfg.dmacssau = ((tempAdd >> 15) & 0xFFFF); 
     dmaTxSynEvt = DMA_DMACCR_SYNC_XEVT1;
     dmaTxCfg.dmaccr |= DMA_FMK(DMACCR,SYNC,dmaTxSynEvt); 
     DMA_config(hDmaTx,&dmaTxCfg); 

     /* Setup Rx Side addresses based on MCBSP port */
     DMA_getConfig(hDmaRx, &dmaRxCfg);
     dmaRxSrc  = MCBSP_ADDR(DRR11) << 1; 
     dmaRxCfg.dmacssal = (DMA_AdrPtr)(dmaRxSrc & 0xFFFF);
     dmaRxCfg.dmacssau = ((dmaRxSrc >> 15) & 0xFFFF);
     tempAdd = (LgUns)(rxstart) << 1; /* byte address */
     dmaRxCfg.dmacdsal = (DMA_AdrPtr)(tempAdd & 0xFFFF);
     dmaRxCfg.dmacdsau = ((tempAdd >> 15) & 0xFFFF); 
     dmaRxSynEvt = DMA_DMACCR_SYNC_REVT1;
     dmaRxCfg.dmaccr |= DMA_FMK(DMACCR,SYNC,dmaRxSynEvt); 
     DMA_config(hDmaRx,&dmaRxCfg); 

     /* Configure DMA to be free running */
     DMA_FSET(DMAGCR,FREE,1); 
     /* Obtain Interrupt IDs for Tx and Rx DMAs */
     rxId = DMA_getEventId(hDmaRx);
     txId = DMA_getEventId(hDmaTx); 
     /* plug in the ISR */
     hwiAttrs.ier0mask = UARTHW_MCBSP_IER_MASK_DEFAULT;
     hwiAttrs.ier1mask = UARTHW_MCBSP_IER_MASK_DEFAULT;
     hwiAttrs.arg = NULL;
     HWI_dispatchPlug(rxId, (Fxn)rxIsr, &hwiAttrs);
     hwiAttrs.ier0mask = UARTHW_MCBSP_IER_MASK_DEFAULT;
     hwiAttrs.ier1mask = UARTHW_MCBSP_IER_MASK_DEFAULT;
     HWI_dispatchPlug(txId, (Fxn)txIsr, &hwiAttrs); 
     IRQ_enable(txId); 
     IRQ_enable(rxId);
}
예제 #2
0
파일: main.c 프로젝트: mewashin/SPH
/**
 * main method
 * contains main run loop
 */
int main() {
	//prototype for linear assembly convolution function
	extern int convolve_as_func(int x[], int w[], int x_idx, int w_length);
	
	DSK6713_init();
	hCodec = DSK6713_AIC23_openCodec(0,&config);
	DSK6713_AIC23_setFreq(hCodec, DSK6713_AIC23_FREQ_8KHZ);

	// enable interrupts
	IRQ_globalEnable();
	IRQ_enable(IRQ_EVT_RINT1);
	IRQ_enable(IRQ_EVT_XINT1);
	
	reset();	// init the input buffer to zeros

	// get the time to make a clock() funciton call; used only for profiling
	/*
	start = clock();
	end = clock();
	diff = end - start;
	*/

	// the first write is needed to trigger the transmit interrupt
	while(!DSK6713_AIC23_write(hCodec, 0));
	in_channel_flag = 1;
	out_channel_flag = 1;

	while(1) {
		if(input_ready) {
			//process sample when input is ready
			sig_error = process_sample(in_left, in_right);
			input_ready = 0;
		}

		// set output when ready
		if(output_ready) {
			out_left = in_left;
			out_right = sig_error;
			output_ready = 0;
		}
	};
	

	/* The program will never exit this loop */
	/* However, if you _do_ exit the loop (say, using a break
	 * statement) close the D/A converter properly */
	DSK6713_AIC23_closeCodec(hCodec);
	exit();
}
예제 #3
0
파일: bsp.c 프로젝트: voileravi/zen
/*..........................................................................*/
void QF_onStartup(void) {
                      /* configuration of Timer0 as the system clock tick...*/
    CSL_TIM_0_REGS->TIMPRD1 = (CPU_CLOCK_HZ / 4096U) / BSP_TICKS_PER_SEC;
    CSL_TIM_0_REGS->TIMPRD2 = 0U;
    CSL_TIM_0_REGS->TIMCNT1 = 0U;
    CSL_TIM_0_REGS->TIMCNT2 = 0U;
    CSL_SYSCTRL_REGS->TIAFR = 0x0007U;      /* clear timer aggregation reg. */
    CSL_TIM_0_REGS->TCR     = 0x802FU;     /* autoReload | prescaler = 4096 */
    IRQ_enable(TINT_EVENT);                    /* enable the TINT interrupt */

    /* setup the RTC interrupt for testing */
    CSL_RTC_REGS->RTCINTEN  = 1U;                  /* enable RTC interrupts */
    CSL_RTC_REGS->RTCINTREG = 1U;  /* enable millisecond periodic interrupt */
    IRQ_enable(RTC_EVENT);
}
예제 #4
0
void main()
{
	//initialize intermediary values to zero
	for(n = 0; n < 11; n++)
	{
		w[n] = 0;
	}

	DSK6713_init();		// Initialize the board support library, must be called first
    hCodec = DSK6713_AIC23_openCodec(0, &config);	// open codec and get handle

	// Configure buffered serial ports for 32 bit operation
	// This allows transfer of both right and left channels in one read/write
	MCBSP_FSETS(SPCR1, RINTM, FRM);
	MCBSP_FSETS(SPCR1, XINTM, FRM);
	MCBSP_FSETS(RCR1, RWDLEN1, 32BIT);
	MCBSP_FSETS(XCR1, XWDLEN1, 32BIT);

	// set codec sampling frequency
	DSK6713_AIC23_setFreq(hCodec, DSK6713_AIC23_FREQ_16KHZ);

	// interrupt setup
	IRQ_globalDisable();			// Globally disables interrupts
	IRQ_nmiEnable();				// Enables the NMI interrupt
	IRQ_map(IRQ_EVT_RINT1,15);		// Maps an event to a physical interrupt
	IRQ_enable(IRQ_EVT_RINT1);		// Enables the event
	IRQ_globalEnable();				// Globally enables interrupts

	while(1)						// main loop - do nothing but wait for interrupts
	{
	}
}
예제 #5
0
/********************************** init_HWI() **************************************/  
void init_HWI(void)
{
	IRQ_globalDisable();			// Globally disables interrupts
	IRQ_nmiEnable();				// Enables the NMI interrupt (used by the debugger)
	IRQ_map(IRQ_EVT_XINT1,4);		// Maps an event to a physical interrupt
	IRQ_enable(IRQ_EVT_XINT1);		// Enables the event
	IRQ_globalEnable();				// Globally enables interrupts
} 
예제 #6
0
void config_interrupts(void)
{
	IRQ_map(IRQ_EVT_EDMAINT, 8);		// CHECK same settings in BIOS!!!
	IRQ_clear(IRQ_EVT_EDMAINT);
	IRQ_enable(IRQ_EVT_EDMAINT);

	SWI_enable();

	IRQ_globalEnable();
}
예제 #7
0
int main(void) {

	/* Initialize the CSL and the CPLD */
	CSL_init();
	DSK6713_init();
	DSK6713_LED_init();

	/* Turn on one LED so we can see it executed at least the main function */
	DSK6713_LED_on(0);

	/* Initialize the DIP switches to be able to read them */
	DSK6713_DIP_init();


	/* Configure the codec according to the definitions in config_AIC23.c
	 * via the McBSP0 interface
	 */
	conf_AIC23();

	/* Configure the McBSP to transfer the data from and to the codec */
	conf_MCBSP();

	/* Start the MCBSP */
	start_MCBSP();

	/* Configure EDMA */
	conf_EDMA();

	/* Time to initialize the buffer and zerofill it */
	for(i = 0; i < 10; i++) FIFO_I[i] = 0;
	for(i = 0; i < 10; i++) FIFO_Q[i] = 0;


	/* Config Interrupts */
	IRQ_enable(IRQ_EVT_EDMAINT);
	IRQ_map(IRQ_EVT_EDMAINT, 8);
	IRQ_globalEnable();

	/* Enable the EDMA channels */
	EDMA_enableChannel(hEDMATrx);


	/******************************************************/
	/* We should be done here by now. The McBSP generates an
	 * Interrupt (called "event" in this case) each time
	 * there's a new word ready to be written or ready to
	 * be transferred from the serial port to the
	 * input buffer. We use it for the golden wire config
	 * and will disable the input when we throw in the
	 * QPSK modulation algorithm as it is not needed by then.
	 */
	/******************************************************/

	/* End main - RTOS takes over */
}
예제 #8
0
void init_Ints(void)  // used to generate sinusoid with interrupts
{
	IRQ_setVecs(vectors);
	IRQ_map(IRQ_EVT_XINT1,11);
	IRQ_reset(IRQ_EVT_XINT1);
	IRQ_enable(IRQ_EVT_XINT1);
	IRQ_nmiEnable();
	IRQ_globalEnable();



}
예제 #9
0
파일: skeleton.c 프로젝트: Quaxxx/RPSS16
void config_interrupts(void)
{
	LOG_printf(&myLog, "config interrupts begin");

	//Wie muss das mapping genau stattfinden?
	// McBSP --> EDMA ?
	// EDMA --> CPU ?
//	IRQ_globalDisable();
	IRQ_map(IRQ_EVT_EDMAINT, 8);			//	EIGEN!!!:		Ist hier 8 richtig?
	IRQ_clear(IRQ_EVT_EDMAINT);				//	EIGEN!!!:
	IRQ_enable(IRQ_EVT_EDMAINT);			//	EIGEN!!!:
	IRQ_globalEnable();

	LOG_printf(&myLog, "config interrupts end");
}
예제 #10
0
void init_Ints(void)  // used to generate sinusoid with interrupts
{
	IRQ_setVecs(vectors);
	IRQ_reset(IRQ_EVT_XINT1);
	IRQ_map(IRQ_EVT_XINT1,11);
	IRQ_nmiEnable();
	IRQ_globalEnable();
	IRQ_enable(IRQ_EVT_XINT1);



	/* add your mappings to set up your interrupt (mcbsp, edma etc) here */




}
예제 #11
0
/**
 *  \brief  Interrupt Dispatcher to identify interrupt source
 *
 *  This function identify the type of UART interrupt generated and
 *  calls concerned ISR to handle the interrupt
 *
 *  \param  none
 *
 *  \return none
 */
interrupt void UART_intrDispatch(void)
{
	Uint16 eventId = 0;

	IRQ_disable(UART_EVENT);

	/* Get the event Id which caused interrupt */
	eventId = UART_getEventId(hUart);

	if (((void (*)(void))(hUart->UART_isrDispatchTable[eventId])))
	{
		((void (*)(void))(hUart->UART_isrDispatchTable[eventId]))();
	}

	IRQ_enable(UART_EVENT);

	return;
}
예제 #12
0
void		convInit( )
{
	convObject.unMillimetersPerTrigger = CONV_MILLIMETERS_PER_TRIGGER;
	convObject.unLastTicks = 0;
	convObject.unLastDeltaTicks = 0;
	convObject.unNumTotalTriggerSignals = 0;
	convObject.unTimeoutTicks = timeFromMs( convHal.unTimeout );
	convObject.bStanding = TRUE;
	
	// PRE: the HWI link to our handler function is set by the config tool.
	IRQ_clear( convHal.unExtInterrupt );
	IRQ_enable( convHal.unExtInterrupt );
	
	// Enable the interrupt in the FPGA
	ppuMemory[CONV_REG_INTENABLE_ADDR] |= CONV_REG_INTENABLE_MASK;
	
	// Init the high res timer that we're going to use
	timeInit();
}
예제 #13
0
void main()
{
	DSK6713_init();		// Initialize the board support library, must be called first
    hCodec = DSK6713_AIC23_openCodec(0, &config);	// open codec and get handle

    //convert coefficients to Q15 format
    short i,j;
    for(i = 0; i < 33; i++)
    {
    	w[i] = 0;
    }

    for(i = 0; i < 11; i++)
    {
    	for(j = 0; j < 3; j++)
    	{
    		NUM_s[i][j] = NUM[i][j] << 5;
    		DEN_s[i][j] = DEN[i][j] << 5;
    	}
    }

	// Configure buffered serial ports for 32 bit operation
	// This allows transfer of both right and left channels in one read/write
	MCBSP_FSETS(SPCR1, RINTM, FRM);
	MCBSP_FSETS(SPCR1, XINTM, FRM);
	MCBSP_FSETS(RCR1, RWDLEN1, 32BIT);
	MCBSP_FSETS(XCR1, XWDLEN1, 32BIT);

	// set codec sampling frequency
	DSK6713_AIC23_setFreq(hCodec, DSK6713_AIC23_FREQ_16KHZ);

	// interrupt setup
	IRQ_globalDisable();			// Globally disables interrupts
	IRQ_nmiEnable();				// Enables the NMI interrupt
	IRQ_map(IRQ_EVT_RINT1,15);		// Maps an event to a physical interrupt
	IRQ_enable(IRQ_EVT_RINT1);		// Enables the event
	IRQ_globalEnable();				// Globally enables interrupts

	while(1)						// main loop - do nothing but wait for interrupts
	{
	}
}
예제 #14
0
// for communication/init using interrupt
void comm_intr() {

	// 0 since not polling
	poll=0;

   	// disable interrupts
	IRQ_globalDisable();

	// init DSP and codec
	c6713_dsk_init();

	// McBSP1 Xmit
	CODECEventId=MCBSP_getXmtEventId(DSK6713_AIC23_codecdatahandle);

	// do not need to point to vector table
	#ifndef using_bios
	//point to the IRQ vector table
	IRQ_setVecs(vectors);
	//since interrupt vector handles this
	#endif

	// map McBSP1 Xmit to INT11
  	IRQ_map(CODECEventId, 11);

 	// reset codec INT 11
  	IRQ_reset(CODECEventId);

  	// globally enable interrupts
  	IRQ_globalEnable();

	// enable NMI interrupt
  	IRQ_nmiEnable();

  	// enable CODEC eventXmit INT11
  	IRQ_enable(CODECEventId);

	// start McBSP interrupt outputting a sample
	output_sample(0);
}
예제 #15
0
파일: Exp2.c 프로젝트: jacyzon/DSP-LAB
/*
 *  initIrq() - Initialize and enable the DMA receive interrupt using the CSL.
 *              The interrupt service routine for this interrupt is edmaHwi.
 */
void initIrq(void)
{
    /* Enable EDMA interrupts to the CPU */
    IRQ_clear(IRQ_EVT_EDMAINT);    // Clear any pending EDMA interrupts
    IRQ_enable(IRQ_EVT_EDMAINT);   // Enable EDMA interrupt
}
예제 #16
0
void main()
{


	// initialize the save buffers
	for(j = 0; j < 2; j++){
		for (i=0;i<SAVES;i++) {
			cde_save[i] = 0;
			pcf_save[i] = 0;
			clockoffset_save[i] = 0.0;
			fde_save[i] = 0.0;
			imax_save[i] = 0;
			recbuf_start_clock_save[i] = 0;
			ppm_estimate_save[i] = 0.0;
			ytilde_save[i] = 0.0;
			state_prediction[j][i] = 0.0;
			state_estimate[j][i] = 0.0;
		}
	}

	// set up the fractionally shifted buffers
	for(k = 0; k < FER; k++){
		fractionalShift = ((double) k )/((double) FER); // number of samples to shift
		for (i=-N;i<=N;i++){
			x = ((double) i - fractionalShift)*BW;
			if (x==0.0) {
				y = 32767.0;
			}
			else
			{
				t = ((double) i - fractionalShift)*CBW;
				y = 32767.0*cos(2*PI*t)*sin(PI*x)/(PI*x); // double
			}
			j = i;
			if (j<0) {
				j += L; // wrap
			}
			allMyDelayedWaveforms[k][j] = (short) y;
		}
	}

	// set up the cosine and sin matched filters for searching
	// also initialize searching buffer
	for (i=0;i<M;i++){
		t = i*CBW;				// time
		y = cos(2*PI*t);		// cosine matched filter (double)
		mfc[i] = (float) y;		// cast and store
		y = sin(2*PI*t);		// sine matched filter (double)
		mfs[i] = (float) y;     // cast and store
		buf[i] = 0;             // clear searching buffer
	}

	// initialize clock buffers
	for (i=0;i<L;i++) {
		clockbuf[i] = 0;
		clockbuf_shifted[0][i] = 0;
		clockbuf_shifted[1][i] = 0;
	}

	// initialize sinc pulse buffer
	for (i=0;i<LL;i++)
		sincpulsebuf[i] = 0;

	// set up clock buffer and sinc pulse buffer
	// to play modulated sinc centered at zero
	for (i=-N;i<=N;i++){
		x = i*BW;
		if (i!=0) {
			t = i*CBW;
			y = 32767.0*cos(2*PI*t)*sin(PI*x)/(PI*x); // double
		}
		else {
			y = 32767.0;
		}
		j = i;
		if (j<0) {
			j += L; // wrap
		}
		clockbuf[j] = (short) y;
		j = i;
		if (j<0) {
			j += LL; // wrap
		}
		sincpulsebuf[j] = (short) y;
	}

	// set up inphase and quadrature sinc pulses for coarse and fine delay estimators
	j = 0;
	for (i=-N;i<=N;i++){
		x = i*BW;
		if (i!=0) {
			t = i*CBW;
			si[j] = (float) (cos(2*PI*t)*sin(PI*x)/(PI*x));
			sq[j] = (float) (sin(2*PI*t)*sin(PI*x)/(PI*x));
		}
		else {
			si[j] = 1.0;
			sq[j] = 0.0;
		}
		j++;
	}

	DSK6713_init();		// Initialize the board support library, must be called first
	DSK6713_LED_init(); // initialize LEDs
    hCodec = DSK6713_AIC23_openCodec(0, &config);	// open codec and get handle

	// Configure buffered serial ports for 32 bit operation
	// This allows transfer of both right and left channels in one read/write
	MCBSP_FSETS(SPCR1, RINTM, FRM);
	MCBSP_FSETS(SPCR1, XINTM, FRM);
	MCBSP_FSETS(RCR1, RWDLEN1, 32BIT);
	MCBSP_FSETS(XCR1, XWDLEN1, 32BIT);

	// set codec sampling frequency
	DSK6713_AIC23_setFreq(hCodec, DSK6713_AIC23_FREQ_8KHZ);

	// interrupt setup
	IRQ_globalDisable();			// Globally disables interrupts
	IRQ_nmiEnable();				// Enables the NMI interrupt
	IRQ_map(IRQ_EVT_RINT1,15);		// Maps an event to a physical interrupt
	IRQ_enable(IRQ_EVT_RINT1);		// Enables the event
	IRQ_globalEnable();				// Globally enables interrupts

	DSK6713_LED_toggle(3);

	while(1)						// main loop
	{
		if ((state==2)&&(delay_est_done==0)){  // TIME TO COMPUTE DELAY ESTIMATES

			DSK6713_LED_toggle(1);	// toggle LED here for diagnostics

			/*****************
			 * 				 *
			 * ESTIMATION    *
			 * 				 *
			 ****************/

			// compute coarse delay estimate
			zmax = 0.0;				// maximum
			imax = 0;				// index of maximum
			for (i=0;i<(2*M-1);i++){  // lag index
				z = 0;
				for (j=0;j<(2*N+1);j++) {
					z+= si[j]*recbuf[i+j];  // correlation at lag i
				}
				if (abs(z)>zmax) {
					zmax = abs(z);  // store maximum
					imax = i;       // store index of maximum
				}
			}
			cde = recbuf_start_clock + imax + N;  // coarse delay estimate (DRB: +N here because si is already shifted by N)
			// cde  is the number of samples elapsed since we launched the S->M sinc pulse

		    // compute fine delay estimate
			zi = 0.0;  // in phase
			zq = 0.0;  // quadrature
			for (j=0;j<(2*N+1);j++) {
				zi+= si[j]*recbuf[imax+j];  // correlation at lag imax
				zq+= sq[j]*recbuf[imax+j];  // correlation at lag imax
			}
			pcf = atan2(zq,zi)*(2*INVPI); // assumes wc = pi/2
			fde = (float) cde + pcf;

			// compute actual clock offset
			// the value computed here is always non-negative and
			// represents the number of samples the master clock is ahead of the slave clock
			// (or the number of samples the slave clock is behind the master clock)
			// S->M sinc pulse was launched at time 0
			// M->S sinc pulse was received at time fde (should be positive)
			// to synchronize, we want slave clock ticks to appear at fde/2 + k*L for k=0,1,....
			clockoffset = fde*0.5;

			// testing/debugging
			imax_save[save_index] = imax;
			recbuf_start_clock_save[save_index] = recbuf_start_clock;
			cde_save[save_index] = cde;
			pcf_save[save_index] = pcf;
			fde_save[save_index] = fde;
			clockoffset_save[save_index] = clockoffset;


			//If first time running
			if(!hasSaved && save_index == 0){
			   state_estimate[0][0] = clockoffset* TS;
			   state_estimate[1][0] = 0;
			   state_prediction[0][1] = clockoffset * TS;
			   state_prediction[1][1] = 0;
			}

			else
			{   // save_index > 0
			    ytilde = clockoffset * TS - state_prediction[0][save_index];  // innovation (difference between current observation and prediction)


			    state_estimate[0][save_index] = state_prediction[0][save_index] + ((double) K1)*ytilde;  // filtered clock offset estimate
			    state_estimate[1][save_index] = state_prediction[1][save_index] + ((double)K2)*ytilde;  // filtered frequency offset estimate

			    //Determine if a glitch has happened


			    if (save_index+1<SAVES) {
			        // generate predictions for next observation (make sure multiplication by LL doesn't cause datatype problems)
			        state_prediction[0][save_index+1] = state_estimate[0][save_index] +  state_estimate[1][save_index] * (double)T0;//* LL;
			        state_prediction[1][save_index+1] = state_estimate[1][save_index];
			    }
			    else if(save_index + 1 == SAVES){
			    	state_prediction[0][0] = state_estimate[0][save_index] + state_estimate[1][save_index]* (double)T0;//* LL;
			    	state_prediction[1][0] = state_prediction[1][save_index];
			    }
			}

			//Calculate the rate offset
			if(!hasSaved && save_index < 1){
				if(save_index == 0)
					rateoffset_estimate = 0;
				else
					rateoffset_estimate = TS * (clockoffset_save[save_index] - clockoffset_save[save_index - 1]);
			}

			//Otherwise, use kalman filter
			else{
				rateoffset_estimate = state_prediction[0][save_index] - state_estimate[0][save_index];

			}

			//

			if(clockoffset_save[save_index] > L && clockoffset_save[save_index - 1] < L)
				adjustedclockoffset = clockoffset_save[save_index] + 5 * L * rateoffset_estimate;
			else if(clockoffset_save[save_index] > L && clockoffset_save[save_index - 1] < L)
				adjustedclockoffset = clockoffset_save[save_index] + 3 * L *rateoffset_estimate;
			else
				adjustedclockoffset = clockoffset_save[save_index] + 4 * L * rateoffset_estimate;
			////////


			j = (short) adjustedclockoffset; // casting from float to short just truncates, e.g., 3.99 becomes 3
			fractionalShift = adjustedclockoffset - (double) j; // fractionalShift >= 0 and < 1 tells us how much of a sample is left
			k = (short) (fractionalShift * (double) FER + 0.5);  // this now rounds and givse results on 0,...,FER
			if (k==FER) {  // we rounded up to the next whole sample
				k = 0;
				j++;
			}
			for (i=0;i<L;i++) {
				ell = j+i;

				while (ell>=L) {
					ell = ell-L;
				}

				if (current_clockbuf==0) {
					clockbuf_shifted[1][ell] = allMyDelayedWaveforms[k][i];  // write other buffer
				}
				else {
					clockbuf_shifted[0][ell] = allMyDelayedWaveforms[k][i];  // write other buffer
				}

			}

			// when can we swap buffers?
			buffer_swap_index = j+L/2;  // midpoint of the silent part (I think)
			while (buffer_swap_index>=L)
				buffer_swap_index = buffer_swap_index-L;

			// tell the ISR the calculations are done
			delay_est_done = 1;

			// update save index
			save_index++;
			if (save_index>=SAVES)  // wrap
				{
				save_index = 0;
				hasSaved = 1;
				}

			DSK6713_LED_toggle(1);	// toggle LED here for diagnostics

		}
		else if (buffer_just_swapped==1) {
			// this code computes the next buffer and attempts to corect for the frequency offset
			buffer_just_swapped = 0;
			// copy appropriate fractionally shifted clock buffer to shifted clock buffer
			adjustedclockoffset = adjustedclockoffset + ((double) L)*one_over_beta;  // adjust latency of next pulse
			while (adjustedclockoffset>((double) L))
				adjustedclockoffset = adjustedclockoffset - (double) L;
			j = (short) adjustedclockoffset; // casting from float to short just truncates, e.g., 3.99 becomes 3
			fractionalShift = adjustedclockoffset - (double) j; // fractionalShift >= 0 and < 1 tells us how much of a sample is left
			k = (short) (fractionalShift * (double) FER);  // this also truncates and should give result on 0,...,FER-1
			for (i=0;i<L;i++) {
				ell = j+i;
				if (ell>=L) {
					ell = ell-L;
				}
				if (current_clockbuf==0) {
					clockbuf_shifted[1][ell] = allMyDelayedWaveforms[k][i];  // write other buffer
				}
				else {
					clockbuf_shifted[0][ell] = allMyDelayedWaveforms[k][i];  // write other buffer
				}

			}
		} // if ((state==2)&&(delay_est_done==0))
	}  // while(1)
}  // void main
예제 #17
0
파일: usb.c 프로젝트: psucurran/NoiseNinjas
/*
 *  usb_test()
 *    USB Bulk transfer test. Device is detected as an eZDSP5535 when
 *    connected to PC while test is running. Bulk transfers can be
 *    made using USB_55xx program.
 *
 */
CSL_Status usb_test(void)
{
	CSL_IRQ_Config    config;
	CSL_Status        result;
	Uint16            eventMask;

	result = CSL_USB_TEST_FAILED;

	usbConfig.opMode             = CSL_USB_OPMODE_POLLED;
    usbConfig.devNum             = CSL_USB0;
	usbConfig.maxCurrent         = CSL_USB_MAX_CURRENT;
	usbConfig.appSuspendCallBack = (CSL_USB_APP_CALLBACK)CSL_suspendCallBack;
	usbConfig.appWakeupCallBack  = (CSL_USB_APP_CALLBACK)CSL_selfWakeupCallBack;
	usbConfig.startTransferCallback  = CSL_startTransferCallback;
	usbConfig.completeTransferCallback = CSL_completeTransferCallback;

	hEpObjArray[0] = &usbCtrlOutEpObj;
	hEpObjArray[1] = &usbCtrlInEpObj;
	hEpObjArray[2] = &usbBulkOutEpObj;
	hEpObjArray[3] = &usbBulkInEpObj;

	/* Set the interrupt vector start address */
	IRQ_setVecs((Uint32)(&VECSTART));

	/* Plug the USB Isr into vector table */
	config.funcAddr = &usb_isr;
	IRQ_plug(USB_EVENT, config.funcAddr);

	/* Enable USB Interrupts */
	IRQ_enable(USB_EVENT);
	/* Enable CPU Interrupts */
	IRQ_globalEnable();

	/* Initialize the USB module */
	status = USB_init(&usbConfig);
	if(status != CSL_SOK)
	{
		printf("USB init failed\n");
		return(result);
	}

	/* Reset the USB device */
	status = USB_resetDev(CSL_USB0);
	if(status != CSL_SOK)
	{
		printf("USB Reset failed\n");
		return(result);
	}

	/* Initialize the Control Endpoint OUT 0 */
	eventMask = (CSL_USB_EVENT_RESET | CSL_USB_EVENT_SETUP |
				 CSL_USB_EVENT_SUSPEND | CSL_USB_EVENT_RESUME |
				 CSL_USB_EVENT_RESET | CSL_USB_EVENT_EOT);

	status = USB_initEndptObj(CSL_USB0, hEpObjArray[0],
	                          CSL_USB_OUT_EP0,CSL_USB_CTRL,
					          CSL_USB_EP0_PACKET_SIZE, eventMask, NULL);
	if(status != CSL_SOK)
	{
		printf("USB End point init failed\n");
		return(result);
	}

	/* Initialize the Control Endpoint IN 0 */
	status = USB_initEndptObj(CSL_USB0, hEpObjArray[1], CSL_USB_IN_EP0,
	                          CSL_USB_CTRL, CSL_USB_EP0_PACKET_SIZE,
	                          CSL_USB_EVENT_EOT, NULL);
	if(status != CSL_SOK)
	{
		printf("USB End point init failed\n");
		return(result);
	}

	/* Initialize the Bulk Endpoint IN 1 */
	eventMask = (CSL_USB_EVENT_RESET | CSL_USB_EVENT_EOT);
	status = USB_initEndptObj(CSL_USB0, hEpObjArray[2], CSL_USB_IN_EP1,
	                          CSL_USB_BULK, CSL_USB_EP1_PACKET_SIZE_FS,
	                          eventMask, NULL);
	if(status != CSL_SOK)
	{
		printf("USB End point init failed\n");
		return(result);
	}

	/* Initialize the Bulk Endpoint OUT 2 */
	status = USB_initEndptObj(CSL_USB0, hEpObjArray[3], CSL_USB_OUT_EP1,
	                          CSL_USB_BULK, CSL_USB_EP1_PACKET_SIZE_FS,
	                          CSL_USB_EVENT_EOT, NULL);
	if(status != CSL_SOK)
	{
		printf("USB End point init failed\n");
		return(result);
	}

	/* Set the parameters */
	status = USB_setParams(CSL_USB0, hEpObjArray, FALSE);
	if(status != CSL_SOK)
	{
		printf("USB Set params failed\n");
		return(result);
	}

	/* Connect the USB device */
	status = USB_connectDev(CSL_USB0);
	if(status != CSL_SOK)
	{
		printf("USB Connect failed\n");
		return(result);
	}

	deviceDescPtr = (Uint16 *)deviceDesc;
	cfgDescPtr    = (Uint16 *)cfgDesc;
	strDescPtr    = (Uint16 *)strDesc;
	dataReadBuffPtr  = (Uint16 *)dataReadBuff;
	dataWriteBuffPtr = (Uint16 *)dataWriteBuff;
	
	while(stopRunning != TRUE);

	result = CSL_USB_TEST_PASSED;
	return(result);
}
예제 #18
0
/**
 *  \brief  UART interrupt Test function
 *
 *   This function verifies the UART operation in interrupt mode.
 *   This function runs in an infinite loop to read the characters
 *   from HyperTerminal and echo the characters back to HyperTerminal.
 *
 *  \param  none
 *
 *  \return Test result(Only Failure Case)
 */
CSL_Status uart_IntcSample(void)
{
	CSL_UartIsrAddr    isrAddr;
	CSL_Status         status;
	Uint32            sysClk;

	sysClk = getSysClk();

	mySetup.clkInput = sysClk;

    /* Loop counter and error flag */
    status = UART_init(&uartObj,CSL_UART_INST_0,UART_INTERRUPT);
    if(CSL_SOK != status)
    {
        printf("UART_init failed error code %d\n",status);
        return(status);
    }
	else
	{
		printf("UART_init Successful\n");
	}

    /* Handle created */
    hUart = (CSL_UartHandle)(&uartObj);

    /* Configure UART registers using setup structure */
    status = UART_setup(hUart,&mySetup);
    if(CSL_SOK != status)
    {
        printf("UART_setup failed error code %d\n",status);
        return(status);
    }
	else
	{
		printf("UART_setup Successful\n");
	}

	/* Send the details of the test to HyperTerminal */
   	status = UART_fputs(hUart,"\r\n\nUART INTERRUPT TEST!",0);
    if(CSL_SOK != status)
    {
        printf("UART_fputs failed error code %d\n",status);
        return(status);
    }

   	status = UART_fputs(hUart,"\r\nTEST READS A CHARACTER FROM HYPERTERMINAL CONTINUOUSLY",0);
    if(CSL_SOK != status)
    {
        printf("UART_fputs failed error code %d\n",status);
        return(status);
    }

   	status = UART_fputs(hUart,"\r\nENTER '$' TO END THE TEST\r\n",0);
    if(CSL_SOK != status)
    {
        printf("UART_fputs failed error code %d\n",status);
        return(status);
    }

	/* Configure and Register the UART interrupts */
	isrAddr.rbiAddr  = uart_rxIsr;
	isrAddr.tbeiAddr = uart_txIsr;
	isrAddr.ctoi     = uart_ctoIsr;
	isrAddr.lsiAddr  = uart_lsiIsr;

    /* Disable interrupt */
    IRQ_globalDisable();

    /* Clear any pending interrupts */
	IRQ_clearAll();

	/* Disable all the interrupts */
	IRQ_disableAll();

	IRQ_setVecs((Uint32)(&VECSTART));

	/* Configuring Interrupt */
	IRQ_plug (UART_EVENT, &UART_intrDispatch);

	/* Enabling Interrupt */
	IRQ_enable(UART_EVENT);
	IRQ_globalEnable();

	/* Set the UART callback function */
 	status = UART_setCallback(hUart,&isrAddr);
	if(status != CSL_SOK)
	{
		printf("UART_setCallback Failed\n");
		return(status);
	}

 	/* Enable the UART Events */
	status = UART_eventEnable(hUart, CSL_UART_XMITOR_REG_EMPTY_INTERRUPT);
	if(status != CSL_SOK)
	{
		printf("UART_eventEnable Failed\n");
		return(status);
	}

	status = UART_eventEnable(hUart, CSL_UART_RECVOR_REG_DATA_INTERRUPT);
	if(status != CSL_SOK)
	{
		printf("UART_eventEnable Failed\n");
		return(status);
	}

	status = UART_eventEnable(hUart, CSL_UART_RECVOR_LINE_STATUS_INTERRUPT);
	if(status != CSL_SOK)
	{
		printf("UART_eventEnable Failed\n");
		return(status);
	}

	/* Tests runs until users enters Symbol '$' on the HyperTerminal */
	while(endOfTest == FALSE)
	{

	}

	printf("\nUSER ENTERED '$' on HyperTerminal\n");
	printf("END OF TEST!\n");

	/* Disable UART interrupts */
	IRQ_disable(UART_EVENT);

	/* Disable GLobal Interrupts */
	IRQ_globalDisable();

	/* Send the END OF TEST MESSAGE to HyperTerminal */
   	status = UART_fputs(hUart,"\r\n\nYOU HAVE ENTERED '$'.",0);
    if(CSL_SOK != status)
    {
        printf("UART_fputs failed error code %d\n",status);
        return(status);
    }

   	status = UART_fputs(hUart,"\r\nEND OF THE TEST!!\r\n",0);
    if(CSL_SOK != status)
    {
        printf("UART_fputs failed error code %d\n",status);
        return(status);
    }

    /* Disable interrupt */
    IRQ_globalDisable();

    /* Clear any pending interrupts */
	IRQ_clearAll();

	/* Disable all the interrupts */
	IRQ_disableAll();

	return(CSL_SOK);
}
예제 #19
0
void DSK6713_configure_AIC23() {
	/* Configure McBSP0 as control interface for aic23 */
	MCBSP_Handle MCBSP0_handle;
	MCBSP0_handle = MCBSP_open(MCBSP_DEV0, MCBSP_OPEN_RESET);

	MCBSP_config(MCBSP0_handle, &MCBSP0_config);
	MCBSP_start(MCBSP0_handle, MCBSP_XMIT_START | MCBSP_SRGR_START | MCBSP_SRGR_START, 220);

	set_aic23_register(MCBSP0_handle, RESET_REGISTER, 0x0000);
	set_aic23_register(MCBSP0_handle, POWER_DOWN_CONTROL, 0x0000);
	set_aic23_register(MCBSP0_handle, LEFT_LINE_INPUT_CHANNEL_VOLUME, 0x0017);
	set_aic23_register(MCBSP0_handle, RIGHT_LINE_INPUT_CHANNEL_VOLUME, 0x0017);
	set_aic23_register(MCBSP0_handle, LEFT_CHANNEL_HEADPHONE_VOLUME, 0x00f9);
	set_aic23_register(MCBSP0_handle, RIGHT_CHANNEL_HEADPHONE_VOLUME, 0x00f9);
	set_aic23_register(MCBSP0_handle, ANALOG_AUDIO_PATH, 0x0011);			// 00001 0010
	set_aic23_register(MCBSP0_handle, DIGITAL_AUDIO_PATH, 0x0000);			// 000000000
	set_aic23_register(MCBSP0_handle, DIGITAL_AUDIO_INTERFACE_FORMAT, 0x0043);	//0 0100 0001
	set_aic23_register(MCBSP0_handle, SAMPLE_RATE_CONTROL, 0x000d);		// 01100
	set_aic23_register(MCBSP0_handle, DIGITAL_INTERFACE_ACTIVATION, 0x0001);

	/* Configure McBSP1 as data interface for aic23 */
	MCBSP_Handle MCBSP1_handle;
	MCBSP1_handle = MCBSP_open(MCBSP_DEV1, MCBSP_OPEN_RESET);
	MCBSP_config(MCBSP1_handle, &MCBSP1_config);
	MCBSP_start(MCBSP1_handle, MCBSP_XMIT_START|MCBSP_RCV_START|MCBSP_SRGR_FRAMESYNC|MCBSP_SRGR_START, 220);

	/* Configure receive EDMA */
	EDMA_Handle hEdmaRcv;
	EDMA_Handle hEdmaRcvA;
	EDMA_Handle hEdmaRcvB;

	hEdmaRcv = EDMA_open(EDMA_CHA_REVT1, EDMA_OPEN_RESET);
	hEdmaRcvA = EDMA_allocTable(-1);
	hEdmaRcvB = EDMA_allocTable(-1);

	gEdmaRcvConfig.src = MCBSP_getRcvAddr(MCBSP1_handle);		// Get address of DRR
	gTccRcvChan = EDMA_intAlloc(-1);							// get next free transfer complete code
	gEdmaRcvConfig.opt |= EDMA_FMK(OPT, TCC, gTccRcvChan);
	EDMA_config(hEdmaRcv, &gEdmaRcvConfig);
	EDMA_config(hEdmaRcvA, &gEdmaRcvConfig);
	gEdmaRcvConfig.dst = EDMA_DST_OF(gRcvBufferB);
	EDMA_config(hEdmaRcvB, &gEdmaRcvConfig);

	EDMA_link(hEdmaRcv, hEdmaRcvB);
	EDMA_link(hEdmaRcvB, hEdmaRcvA);
	EDMA_link(hEdmaRcvA, hEdmaRcvB);

	/* Configure transmit EDMA */
	EDMA_Handle hEdmaXmt;
	EDMA_Handle hEdmaXmtA;
	EDMA_Handle hEdmaXmtB;

	hEdmaXmt = EDMA_open(EDMA_CHA_XEVT1, EDMA_OPEN_RESET);
	hEdmaXmtA = EDMA_allocTable(-1);
	hEdmaXmtB = EDMA_allocTable(-1);

	gEdmaXmtConfig.dst = MCBSP_getXmtAddr(MCBSP1_handle);		// Get address of DXR
	gTccXmtChan = EDMA_intAlloc(-1);							// get next free transfer complete code
	gEdmaXmtConfig.opt |= EDMA_FMK(OPT, TCC, gTccXmtChan);
	EDMA_config(hEdmaXmt, &gEdmaXmtConfig);
	EDMA_config(hEdmaXmtA, &gEdmaXmtConfig);
	gEdmaXmtConfig.src = EDMA_DST_OF(gXmtBufferB);				// set source to buffer B
	EDMA_config(hEdmaXmtB, &gEdmaXmtConfig);

	EDMA_link(hEdmaXmt, hEdmaXmtB);
	EDMA_link(hEdmaXmtB, hEdmaXmtA);
	EDMA_link(hEdmaXmtA, hEdmaXmtB);


	EDMA_intClear(gTccRcvChan);
	EDMA_intClear(gTccXmtChan);
	EDMA_intEnable(gTccRcvChan);
	EDMA_intEnable(gTccXmtChan);

	gBufferState.cpuBufferState = StateB;		// inittial cpu buffer state

	EDMA_enableChannel(hEdmaRcv);
	EDMA_enableChannel(hEdmaXmt);

	IRQ_clear(IRQ_EVT_EDMAINT);
	IRQ_enable(IRQ_EVT_EDMAINT);

	MCBSP_write(MCBSP1_handle, 0x00);
}
예제 #20
0
파일: main.c 프로젝트: zhanglong71/Demo
int main()
{
    int i;
	msg_t msg;
	func_t func;
	
/** 外设初始化开始 **/
	Peripheral_Init();
/** 外设初始化结束 **/

    charQueueInit(&g_com1TxQue);
    //charQueueInit(&g_com2TxQue);
    MFPACK_FIFO_CLEAN("清空指纹传感器缓冲区");
    MBTACK_FIFO_CLEAN("清空蓝牙接收缓冲区");
    actionQueueInit(&g_actionQueue, &(g_timer[1]), CACT_TOUT, CACT_OVER);
    actionQueueInit(&g_promptQueue, &(g_timer[2]), CPMT_TOUT, CPMT_OVER);
    actionQueueInit(&g_blinkQueue, &(g_timer[3]), CBLK_TOUT, CBLK_OVER);
    
    adcSample_Init(&g_adcData, &(g_timer[4]), CADC_TOUT, TIMER_300MS);
    
    for(i = 0; i < TIMER_NUM; i++) {
        ClrTimer(&g_timer[i]);
    }
    
    //SetTimer(&g_timer[0], TIMER_1SEC, CMSG_TMR);
    msgq_init(&g_msgq);
    
	#if	1
	msg.msgType = CMSG_PWON;
	msgq_in(&g_msgq, &msg);
	
	fstack_init(&g_fstack);
    func.func = f_idle;
    fstack_push(&g_fstack, &func);
	#endif
	
	AWU_Config();
	//enableInterrupts();
	IRQ_enable();
	//MIRQ_disable();
	/* Infinite loop */
	while(1)
	{
        //IWDG_ReloadCounter();
        
       	//Refresh_WWDG_Window();
       	//Test_WWDGReset();
       	
        keyscan();
        //vop_busy();
        //fingerCheck();
        PeripheralInput_Check();
        
        DAEMON_USART1_Send(&g_com1TxQue);   /** output to fingerprint **/
        DAEMON_USART3_Send(&g_com3TxQue);   /** output to bluetooth **/
        //DAEMON_USART1_Recive(&g_comRevBuf);
        
        actionDoing(&g_actionQueue);
        actionDoing(&g_promptQueue);
        actionDoing(&g_blinkQueue);

		if(msgq_out_irq(&g_msgq, &msg) == FALSE) {     	/** 有消息吗? **/
			continue;
		}
		if(sysProcess(&msg) == TRUE) {   			/** 是系统消息吗? **/
			continue;
		}

		if(fstack_top(&g_fstack, &func) == FALSE) {    /** 当前处于工作状态吗? **/
		  /** something wrong happend, Power Down or recover it **/
		  	fstack_init(&g_fstack);
			func.func = f_idle;
			fstack_push(&g_fstack, &func);
			
			g_tick = 0;
			SetTimer_irq(&g_timer[0], TIMER_1SEC, CMSG_TMR);
			continue;
		}
		func.func((unsigned *)&msg);
	}
}
void main()
{

	// set up the cosine and sin matched filters for searching
	// also initialize searching buffer
	for (i=0;i<M;i++){
		t = i*0.25;				// time
		y = cos(2*PI*t);		// cosine matched filter (double)
		mfc[i] = (float) y;		// cast and store
		y = sin(2*PI*t);		// sine matched filter (double)
		mfs[i] = (float) y;     // cast and store
		buf[i] = 0.0;             // clear searching buffer
		fbuf[i] = 0.0;
	}

	// initialize input buffer
	for (i=0;i<BL;i++)
		inbuf[i] = 0.0;

	// initialize clock buffer
	for (i=0;i<L;i++)
		clockbuf[i] = 0;

	// set up clock buffer to play modulated sinc centered at zero
	for (i=-N;i<=N;i++){
		x = i*BW;
		if (i!=0) {
			t = i*0.25;
			y = ((double) CLOCKAMPLITUDE)*cos(CARRIERKHZ*PI*t)*sin(PI*x)/(PI*x); // double
		}
		else {
			y = ((double) CLOCKAMPLITUDE);
		}
		j = i;
		if (j<0) {
			j += L; // wrap
		}
		clockbuf[j] = (short) y;
	}



	DSK6713_init();		// Initialize the board support library, must be called first
	DSK6713_LED_init(); // initialize LEDs
    hCodec = DSK6713_AIC23_openCodec(0, &config);	// open codec and get handle

	// Configure buffered serial ports for 32 bit operation
	// This allows transfer of both right and left channels in one read/write
	MCBSP_FSETS(SPCR1, RINTM, FRM);
	MCBSP_FSETS(SPCR1, XINTM, FRM);
	MCBSP_FSETS(RCR1, RWDLEN1, 32BIT);
	MCBSP_FSETS(XCR1, XWDLEN1, 32BIT);

	// set codec sampling frequency
	DSK6713_AIC23_setFreq(hCodec, DSK6713_AIC23_FREQ_16KHZ);

	// interrupt setup
	IRQ_globalDisable();			// Globally disables interrupts
	IRQ_nmiEnable();				// Enables the NMI interrupt
	IRQ_map(IRQ_EVT_RINT1,15);		// Maps an event to a physical interrupt
	IRQ_enable(IRQ_EVT_RINT1);		// Enables the event
	IRQ_globalEnable();				// Globally enables interrupts

	while(1)						// main loop
	{
	}
}
예제 #22
0
void main()
{
	DSK6713_init();		// Initialize the board support library, must be called first
    hCodec = DSK6713_AIC23_openCodec(0, &config);	// open codec and get handle

	// Configure buffered serial ports for 32 bit operation
	// This allows transfer of both right and left channels in one read/write
	MCBSP_FSETS(SPCR1, RINTM, FRM);
	MCBSP_FSETS(SPCR1, XINTM, FRM);
	MCBSP_FSETS(RCR1, RWDLEN1, 32BIT);
	MCBSP_FSETS(XCR1, XWDLEN1, 32BIT);

	// set codec sampling frequency
	DSK6713_AIC23_setFreq(hCodec, DSK6713_AIC23_FREQ_8KHZ);

	//initialize buffers to zero
	init();

	// interrupt setup
	IRQ_globalDisable();			// Globally disables interrupts
	IRQ_nmiEnable();				// Enables the NMI interrupt
	IRQ_map(IRQ_EVT_RINT1,15);		// Maps an event to a physical interrupt
	IRQ_enable(IRQ_EVT_RINT1);		// Enables the event
	IRQ_globalEnable();				// Globally enables interrupts

	//temporary variable for real-imag swapping for ifft, placed here for convenience
	float temp = 0;

	while(1)						// main loop - do nothing but wait for interrupts
	{
		if(pingFlag == 1){
			for(n = 0; n < FFT_LENGTH; n++){
				if(n < (ORDER - 1)){
					pingU[n] = Z[n];
				}
				else{
					pingU[n] = PING[n - (ORDER - 1)];
				}
			}
//			cfftr2_dit(pingU,w,FFT_LENGTH); //TI floating-pt complex FFT
//			bitrev(pingU,ix,FFT_LENGTH); //freq scrambled->bit-reverse X

			for(n = 0; n < FFT_LENGTH; n++){
//				V[n] = cmplxMult(h[n],pingU[n]);

				V[n] = pingU[n];

				//swap real and imaginary for ifft, remember to uncomment temp as well
//				temp = V[n].re;
//				V[n].re = V[n].im;
//				V[n].im = temp;
			}

//			cfftr2_dit(V,w,FFT_LENGTH) ; //TI floating-pt complex ifft
//			bitrev(V,ix,FFT_LENGTH); //freq scrambled->bit-reverse X

			for(n = ORDER - 1; n < FFT_LENGTH; n++)
			{
				outputPING[n] = V[n].re * 32768;
			}

			for(n = (FFT_LENGTH - (ORDER - 1)) - (ORDER -1); n < FFT_LENGTH - (ORDER - 1); n++)
			{
				Z[n] = PING[n];
			}
			lflag = 1;
		}
		if(pongFlag == 1){
			for(n = 0; n < FFT_LENGTH; n++){
				if(n < (ORDER - 1)){
					pongU[n] = Z[n];
				}
				else{
					pongU[n] = PONG[n - (ORDER - 1)];
				}
			}

//			cfftr2_dit(pongU,w,FFT_LENGTH) ; //TI floating-pt complex FFT
//			bitrev(pongU,ix,FFT_LENGTH); //freq scrambled->bit-reverse X

			for(n = 0; n < FFT_LENGTH; n++){
//				V[n] = cmplxMult(h[n],pongU[n]);

				V[n] = pongU[n];

//				swap real and imaginary for ifft, remember to uncomment temp as well
//				temp = V[n].re;
//				V[n].re = V[n].im;
//				V[n].im = temp;
			}
//			cfftr2_dit(V,w,FFT_LENGTH) ; //TI floating-pt complex ifft
//			bitrev(V,ix,FFT_LENGTH); //freq scrambled->bit-reverse X

			for(n = ORDER - 1; n < FFT_LENGTH; n++)
			{
				outputPONG[n] = V[n].re * 32768;
			}

			for(n = (FFT_LENGTH - (ORDER - 1)) - (ORDER -1); n < FFT_LENGTH - (ORDER - 1); n++)
			{
				Z[n] = PONG[n];
			}
			lflag = 1;
		}
	}
}
/**
 *  \brief  Audio Class intialization function
 *
 *  \param  None
 *
 *  \return None
 */
void CSL_acTest(void)
{
    I2sInitPrms i2sInitPrms;
    CSL_UsbConfig usbConfig;
    PSP_Result result;
    Int16 status;
    HWI_Attrs attrs;


    LOG_printf(&trace, "USB ISO FULL SPEED MODE\n");

    /* Initialize audio module */
    result = AIC3254_init();
    if(result != 0)
    {
        LOG_printf(&trace, "ERROR: Unable to configure audio codec");
    }
    else
    {
#if !defined(SAMPLE_BY_SAMPLE_PB) || !defined(SAMPLE_BY_SAMPLE_REC)
        DMA_HwInit();
        DMA_DrvInit();
#endif

        /* Initialize I2S and associated DMA channels for Playback and Record */
        i2sInitPrms.enablePlayback = TRUE;
        i2sInitPrms.enableStereoPb = TRUE;
#ifdef SAMPLE_BY_SAMPLE_PB
        i2sInitPrms.sampleBySamplePb = TRUE;
#else /* Configuration untested since ASRC only works with I2S in sample-by-sample mode */
        i2sInitPrms.sampleBySamplePb = FALSE;
        i2sInitPrms.enableDmaPingPongPb = FALSE;
        i2sInitPrms.pingI2sTxLeftBuf = ping_i2sTxLeftBuf;
        i2sInitPrms.pongI2sTxLeftBuf = pong_i2sTxLeftBuf;
        i2sInitPrms.pingI2sTxRightBuf = ping_i2sTxRightBuf;
        i2sInitPrms.pongI2sTxRightBuf = pong_i2sTxRightBuf;
        i2sInitPrms.zeroBuf = ZeroBuf;
#endif
        i2sInitPrms.i2sPb = PSP_I2S_TX_INST_ID;
        i2sInitPrms.enableRecord = TRUE;
        i2sInitPrms.enableStereoRec = FALSE;
#ifdef SAMPLE_BY_SAMPLE_REC
        i2sInitPrms.sampleBySampleRec = TRUE;
#else
        i2sInitPrms.sampleBySampleRec = FALSE;
        i2sInitPrms.enableDmaPingPongRec = TRUE;
        i2sInitPrms.pingI2sRxLeftBuf = (Int16 *)ping_pong_i2sRxLeftBuf;
        i2sInitPrms.pongI2sRxLeftBuf = NULL;
        i2sInitPrms.pingI2sRxRightBuf = (Int16 *)ping_pong_i2sRxRightBuf;
        i2sInitPrms.pongI2sRxRightBuf = NULL;
#endif
        i2sInitPrms.i2sRec = PSP_I2S_RX_INST_ID;
        status = i2sInit(&i2sInitPrms);
        if (status != I2SSAMPLE_SOK)
        {
            LOG_printf(&trace, "ERROR: Unable to initialize I2S");
        }

#ifdef C5535_EZDSP_DEMO
		// initialize the OLED display        
        oled_init();
#endif
        
        /* Initialising the Pointer to the Audio Class Handle to the Buffer Allocated */
        AC_AppHandle.pAcObj = &ACAppBuffer[0];

        usbConfig.devNum                = CSL_USB0;
        usbConfig.opMode                = CSL_USB_OPMODE_POLLED;
#ifdef APP_USB_SELF_POWERED
        usbConfig.selfPowered           = TRUE;
#else
        usbConfig.selfPowered           = FALSE;
#endif
        usbConfig.maxCurrent            = APP_USB_MAX_CURRENT;
        usbConfig.appSuspendCallBack    = (CSL_USB_APP_CALLBACK)CSL_suspendCallBack;
        usbConfig.appWakeupCallBack     = (CSL_USB_APP_CALLBACK)CSL_selfWakeupCallBack;
        usbConfig.startTransferCallback  = StartTransfer;
        usbConfig.completeTransferCallback = CompleteTransfer;

        USB_init(&usbConfig);

        USB_setFullSpeedMode(0x40); /* parameter is EP0 data size in bytes */

        USB_resetDev(CSL_USB0);

        /* Calling init routine */
        /* Giving all the table hanldes and the buffers to the Audio Class module */
        AC_AppHandle.strDescrApp = (char **)&string_descriptor[0];
        AC_AppHandle.lbaBufferPbApp = &lbaBufferPbApp[0];
        AC_AppHandle.lbaBufferRecApp = &lbaBufferRecApp[0];
        AC_AppHandle.lbaBufferHidReportApp = &lbaBufferHidReportApp[0];
        AC_AppHandle.acReqTableApp = USB_ReqTable;
        AC_AppHandle.pId = pId;
        AC_AppHandle.vId = vId;

#ifndef ENABLE_PLAYBACK_TWO_SAMPLE_RATES
        #ifdef SAMPLE_RATE_TX_48kHz
        LOG_printf(&trace, "PLAYBACK: 48KHZ ");
        #ifdef ENABLE_STEREO_PLAYBACK
        LOG_printf(&trace, "STEREO\n");
        AC_AppHandle.rxPktSize = EP_PB_MAXP; // max packet size for 48K stereo
        #else // ENABLE_STEREO_PLAYBACK
        LOG_printf(&trace, "MONO\n");
        AC_AppHandle.rxPktSize = 0x60; // max packet size for 48K mono
        #endif // ENABLE_STEREO_PLAYBACK
        #endif // SAMPLE_RATE_TX_48kHz

        #ifdef SAMPLE_RATE_TX_44_1kHz
        LOG_printf(&trace, "PLAYBACK: 44.1KHZ ");
        #ifdef ENABLE_STEREO_PLAYBACK
        LOG_printf(&trace, "STEREO\n");
        AC_AppHandle.rxPktSize = 0xB0; // max packet size for 44.1 stereo
        #else // ENABLE_STEREO_PLAYBACK
        LOG_printf(&trace, "MONO\n");
        AC_AppHandle.rxPktSize = 0x58; // max packet size for 44.1 mono
        #endif // ENABLE_STEREO_PLAYBACK
        #endif // SAMPLE_RATE_TX_44_1kHz

        #ifdef SAMPLE_RATE_TX_32kHz
        LOG_printf(&trace, "PLAYBACK: 32KHZ ");
        #ifdef ENABLE_STEREO_PLAYBACK
        LOG_printf(&trace, "STEREO\n");
        AC_AppHandle.rxPktSize = 0x80; // max packet size for 32K stereo
        #else // ENABLE_STEREO_PLAYBACK
        LOG_printf(&trace, "MONO\n");
        AC_AppHandle.rxPktSize = 0x40; // max packet size for 32K mono
        #endif // ENABLE_STEREO_PLAYBACK
        #endif // SAMPLE_RATE_TX_32kHz

        #ifdef SAMPLE_RATE_TX_16kHz
        LOG_printf(&trace, "PLAYBACK: 16KHZ ");
        #ifdef ENABLE_STEREO_PLAYBACK
        LOG_printf(&trace, "STEREO\n");
        AC_AppHandle.rxPktSize = RX_PKT_SIZE_16K_PLAYBACK_STEREO; // max packet size for 16K stereo
        rx_pkt_size_16K_playback = RX_PKT_SIZE_16K_PLAYBACK_STEREO; // max packet size for 16K stereo
        #else // ENABLE_STEREO_PLAYBACK
        LOG_printf(&trace, "MONO\n");
        AC_AppHandle.rxPktSize = RX_PKT_SIZE_16K_PLAYBACK_MONO; // max packet size for 16K mono
        rx_pkt_size_16K_playback = RX_PKT_SIZE_16K_PLAYBACK_MONO;  // max packet size for 16K mono
        #endif // ENABLE_STEREO_PLAYBACK
        #endif // SAMPLE_RATE_TX_16kHz

#else /* ENABLE_PLAYBACK_TWO_SAMPLE_RATES */
        LOG_printf(&trace, "PLAYBACK: 48KHZ ");
        #ifdef ENABLE_STEREO_PLAYBACK
        LOG_printf(&trace, "STEREO\n");
        AC_AppHandle.rxPktSize = EP_PB_MAXP; // max packet size for 48K stereo
        #else // ENABLE_STEREO_PLAYBACK
        LOG_printf(&trace, "MONO\n");
        AC_AppHandle.rxPktSize = 0x60; // max packet size for 48K mono
        #endif // ENABLE_STEREO_PLAYBACK

        LOG_printf(&trace, "PLAYBACK: 16KHZ ");
        #ifdef ENABLE_STEREO_PLAYBACK
        rx_pkt_size_16K_playback = RX_PKT_SIZE_16K_PLAYBACK_STEREO; // max packet size for 16K stereo
        LOG_printf(&trace, "STEREO\n");
        #else // ENABLE_STEREO_PLAYBACK
        rx_pkt_size_16K_playback = RX_PKT_SIZE_16K_PLAYBACK_MONO;  // max packet size for 16K mono
        LOG_printf(&trace, "MONO\n");
        #endif // ENABLE_STEREO_PLAYBACK
#endif /* ENABLE_PLAYBACK_TWO_SAMPLE_RATES */

        AC_AppHandle.txPktSize = EP_REC_MAXP; // max packet size for 16K mono
        AC_AppHandle.hidTxPktSize = EP_HID_MAXP; // max packet size for HID output report

        /* All Function Handlers need to be Initialised */
        AC_AppHandle.playAudioApp = appPlayAudio;
        AC_AppHandle.recordAudioApp = appRecordAudio;
        AC_AppHandle.initPlayAudioApp = appInitPlayAudio;
        AC_AppHandle.initRecordAudioApp = appInitRecordAudio;
        AC_AppHandle.stopPlayAudioApp = appStopPlayAudio;
        AC_AppHandle.stopRecordAudioApp = appStopRecordAudio;
        AC_AppHandle.mediaGetPresentStateApp = AppGetMediaStatus;
        AC_AppHandle.mediaInitApp = AppMediaInit;
        AC_AppHandle.mediaEjectApp = AppMediaEject;
        AC_AppHandle.mediaLockUnitApp = AppLockMedia;
        AC_AppHandle.getMediaSizeApp = AppGetMediaSize;
        AC_AppHandle.getHidReportApp = appGetHidReport;
        AC_AppHandle.ctrlHandler  = appCtrlFxn;
        AC_AppHandle.isoHandler   = appIsoFxn;
        AC_AppHandle.hidHandler = appHidFxn;

        AC_AppHandle.numLun = 2;

        /* Initialize End point descriptors */
        AC_initDescriptors(AC_AppHandle.pAcObj, (Uint16 *)deviceDescriptorB,
                            CSL_AC_DEVICE_DESCR, sizeof(deviceDescriptorB));

        AC_initDescriptors(AC_AppHandle.pAcObj, (Uint16 *)deviceQualifierDescr,
                            CSL_AC_DEVICE_QUAL_DESCR, 10);

        AC_initDescriptors(AC_AppHandle.pAcObj, (Uint16 *)configDescriptor,
                            CSL_AC_CONFIG_DESCR, sizeof(configDescriptor));

        AC_initDescriptors(AC_AppHandle.pAcObj, (Uint16 *)stringLanId,
                            CSL_AC_STRING_LANGID_DESC, 6);

        AC_initDescriptors(AC_AppHandle.pAcObj, (Uint16 *)acHidReportDescriptor,
                            CSL_AC_HID_REPORT_DESC, sizeof(acHidReportDescriptor));

        /* Initialize HID */
        AC_AppHandle.acHidIfNum = IF_NUM_HID; // HID interface number
        AC_AppHandle.acHidReportId = HID_REPORT_ID; // HID report ID
        AC_AppHandle.acHidReportLen = HID_REPORT_SIZE_BYTES; // HID report length (bytes)
        genHidReport(UI_PUSH_BUTTON_NONE, gHidReport); // init. HID report for Get Report 

        /* Call Init API */
        AC_Open(&AC_AppHandle);

        /* Enable CPU USB interrupts */
        CSL_FINST(CSL_CPU_REGS->IER1, CPU_IER1_USB, ENABLE);

        /* Initialize active sample rate */
        initSampleRate(RATE_48_KHZ, &active_sample_rate, 
            &i2sTxBuffSz);

        /* Initialize ASRC */ 
        Init_Sample_Rate_Converter(active_sample_rate);

        /* Reset codec output buffer */
        reset_codec_output_buffer();

        #ifdef ENABLE_RECORD
        #ifdef SAMPLE_RATE_RX_48kHz
        LOG_printf(&trace, "RECORD: 48KHZ ");
        #else
        LOG_printf(&trace, "RECORD: 16KHZ ");
        #endif // SAMPLE_RATE_RX_48kHz
        // start the rx DMAs
        DMA_StartTransfer(hDmaRxLeft);

        #ifdef ENABLE_STEREO_RECORD
        LOG_printf(&trace, "STEREO  NOT SUPPORTED - RECORD WILL BE MONO\n");
        DMA_StartTransfer(hDmaRxRight);
         #else
        LOG_printf(&trace, "MONO\n");
        #endif

        #endif // ENABLE_RECORD

#ifdef STORE_PARAMETERS_TO_SDRAM
        initSdram(FALSE, 0x0000);
#endif // STORE_PARAMETERS_TO_SDRAM
#ifdef SAMPLE_BY_SAMPLE_PB
        /* SampleBySample, init interrupt */       
        /* Use with compiler "interrupt" keyword */
        //IRQ_plug(I2S_TX_EVENT, i2s_txIsr);
        
        /* Use with dispatcher, no "interrupt" keyword */
        attrs.ier0mask = 0xFFFF;
        attrs.ier1mask = 0xFFFF;
        HWI_dispatchPlug(I2S_TX_EVENT, (Fxn)i2s_txIsr, &attrs);

        IRQ_enable(I2S_TX_EVENT);   /* SampleBySample, enable IRQ for I2S Tx */
#endif
#if defined(SAMPLE_BY_SAMPLE_REC) && !defined(COMBINE_I2S_TX_RX_ISR)
        /* SampleBySample, init interrupt */
        /* Use with compiler "interrupt" keyword */
        IRQ_plug(I2S_RX_EVENT, i2s_rxIsr);
        
        /* Use with dispatcher, no "interrupt" keyword */
        //attrs.ier0mask = 0xFFFF;
        //attrs.ier1mask = 0xFFFF;
        //HWI_dispatchPlug(I2S_RX_EVENT, (Fxn)i2s_rxIsr, &attrs);

        IRQ_enable(I2S_RX_EVENT);    /* SampleBySample, enable IRQ for I2S Rx */
#endif
#if defined(SAMPLE_BY_SAMPLE_PB) || defined(SAMPLE_BY_SAMLE_REC)
        DDC_I2S_transEnable((DDC_I2SHandle)i2sHandleTx, TRUE);    /* SampleBySample, enable I2S transmit and receive */
#endif
#ifndef SAMPLE_BY_SAMPLE_PB
        i2sTxStart(); // - moved from appPlayAudio()
#endif

#ifdef C5535_EZDSP_DEMO
        // clock gating usused peripherals
		ClockGating();
#endif
    }
}