⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 基于ADI blackfin处理器的范例程序
💻 C
字号:
/*****************************************************************************************/
//
// Name: 	BF533 EZ-KIT interface to the AD9866 Mixed-Signal Front-End Evaluation Board 
//
/*****************************************************************************************

(C) Copyright 2004 - Analog Devices, Inc.  All rights reserved.

File Name:				Main.c

Date Modified:			05/07/04		PK		Rev 1.2

Software:       		VisualDSP++3.5

Hardware:				BF533 EZ-KIT Board
						BF533/561 Extender Board
						AD9866 Evaluation Board

Hardware Setup:			See readme.txt
						
Purpose:				This code example demonstrates the functionality of a half-duplex
						communication scheme between an ADSP-BF533 Blackfin processor and
						an AD9866 Broadband Modem Mixed-Signal Front-End. The AD9866 has 
						two high-speed converters on board: a 12-bit 80 MSPS ADC and a 12-bit
						200 MSPS DAC. The digitized analog signal from the ADC is read into
						a DMA buffer via the Blackfin's parallel peripheral interface (PPI). 
						Optionally, some processing is performed on the data and it is then 
						transferred out to the DAC via the PPI. A double-buffering scheme 
						is used to boost processing efficiency. 
						
						
						The source code in process.c contains a commented section that performs
						an FFT followed by an inverse FFT on the input data. This acts as a 
						demonstration of how much processing head-room is available. The user may
						replace this section with any appropriate signal processing algorithms 
						as desired. However, it must be ensured that the processing latency for 
						each data buffer half does not exceed the time interval required for 
						its DMA transfer.
						
						A general-purpose timer on the Blackfin processor is used to generate
						periodic interrupts. These interrupts trigger transitions between the
						4 stages of this scheme:
						
						0. RX First Half						1. RX Second Half / Process First Half
 						2. TX First Half / Process Second Half	3. TX Second Half
						
						The timer period was chosen empirically such that it allows enough time 
						for the appropriate DMA transfers to complete. Additionally, some 
						cycles are required for the DMA controller and PPI to change direction.
						
						A more thorough statistical analysis of the latencies associated with
						the PPI/DMA turnaround will be presented in a future application note.
						
******************************************************************************************/

#include "system.h"


EX_EXCEPTION_HANDLER(ex_handler);


// Declare the DMA input and output buffers
section("L1_data_a") volatile short sPPI_RxBuffer[Number_of_ADC_channels * Number_of_Samples * 2];
section("L1_data_b") volatile short sPPI_TxBuffer[(Number_of_DAC_channels * Number_of_Samples * 2)+33];

// GLOBAL scalars

// flag to indicate which half of the output buffer has been transmitted and can be worked on by the user
// i.e. points to the half that DMA is NOT using
short half = 1;			// 0 = first half, 1 = second half

// 2-bit flag indicating which stage of execution is currently under way

short ping_pong = 0;

// semaphore to indicated that a half has been transmitted 
short stage_initialized = 0;

// store IMASK register when interrupts are disabled
int interruptLatch;

// USER CODE

section("L1_code") void main() {
	int i = 0;
	
	// init exception handler
	register_handler(ik_exception,ex_handler);

	// Set CCLK = 594 MHz, SCLK = 118 MHz
	
	interruptLatch = cli();
	Set_PLL(22,5);
	sti(interruptLatch);
	

#ifdef EZ_KIT
	InitFlash();
#endif
	init_twiddle();

    initFlags();

	InitSPI_for_AD9866();
    Init_AD9866();	

	
	
	//clear receive buffer
	
	for(i=0; i<Number_of_ADC_channels * Number_of_Samples * 2; i++) {
		sPPI_RxBuffer[i] = 0x7FF0;
	}
	
	// Fill the last 33 words of the TX buffer with midscale values
	// This ensures that the TxDAC interpolation filters are flushed 
	// before the TX path is disabled
	
	for(i= Number_of_ADC_channels * Number_of_Samples * 2; i<((Number_of_ADC_channels * Number_of_Samples * 2)+33); i++) {
		sPPI_TxBuffer[i] = 0x0;
	}
	
	// initialise Hardware


	InitInterrupts();
	*pPPI_CONTROL = (short) 0x0000; //Disable PPI
	*pDMA0_CONFIG = 0x0000; // Disable DMA
	*pPPI_CONTROL = (short) 0x387C;	
	*pPPI_DELAY   = 0x1B;
	*pPPI_COUNT   = Number_of_ADC_channels * Number_of_Samples*2;
	*pPPI_FRAME   = 1;
	*pDMA0_CONFIG = 0x6;
	*pDMA0_START_ADDR = sPPI_RxBuffer;
	*pDMA0_X_MODIFY = Number_of_ADC_channels * Word_Size;
	*pDMA0_X_COUNT = Number_of_Samples*2;		
	*pDMA0_CONFIG = *pDMA0_CONFIG | DMAEN;	// enable DMA  (PPI not enabled yet)
	*pPPI_CONTROL |= PORT_EN;				// enable PPI
	*pFIO_FLAG_S = 0x0008;	// RX: Set Flag 3 (RXEN)
	initTimer();
	ssync();
	
	// MAIN loop
	// waits indefinetely for timer interrupts.
	// When an interrupt occurs, the appropriate data buffer half is processed.
	// The DMA transfers to and from the data converters are initiated in the
	// ISR which executes before the next iteration of the main loop.
	
	while(1) {

		// sync to interrupt through semaphore
		
		asm("cli %0;" : "=d" (interruptLatch)); asm("ssync;");
		ssync();
		// Check for the semaphore, and process if semaphore indicates completion
		

		if (stage_initialized == 1)  {
			if ((ping_pong == 0) | (ping_pong == 3)) // Correspond to core idle stages
				stage_initialized = 0;	 // reset the semaphore
			else {
				process();	// process appropriate data half
							// and write output to TX buffer
				stage_initialized = 0;  // reset the semaphore
			
			} 		// Inner IF
		} 		// Outer IF
		ssync();
		asm("sti %0;" : : "d" (interruptLatch)); asm("ssync;");
	}			// WHILE

}			// MAIN


int initFlags() {
	// Configure the flags 0-15 as inputs, exceptPF3, PF2, PF1 and PF0
	*((short *)FIO_DIR) = *((short *)FIO_DIR) & (0x000F);
	*((short *)FIO_DIR) = *((short *)FIO_DIR) | (0x000F);
	
	// Deassert the output flags
  	*pFIO_FLAG_C = (0x000F);
	asm("ssync;");
	return 0;
}



/********************************************************************************/
/***** Init_AD9866()														*****/
/***** Configures the MxFE via the SPI interface							*****/
/***** For further details on this section, consult the AD9866 data sheet   *****/
/********************************************************************************/
void Init_AD9866(void)
{ unsigned char temp =0;	 

	// Low Drive Strength, IAMP disabled
	temp = Write_Byte_to_AD9866(0xE, 0x81);
	// Interpolation Factor = 4, DAC data format = straight binary
	temp = Write_Byte_to_AD9866(0xC, 0x0);		
	// Disable CLKOUT divide-by-two
	temp = Write_Byte_to_AD9866(0x6, 0x00);	
	// Set DAC Power-Down Delay to 0 cycles, disable half-duplex power savings mode
	temp = Write_Byte_to_AD9866(0x3,0x4);
	// Set PLL x4 multiplication for DAC Clock
	temp = Write_Byte_to_AD9866(0x4,0x2);
	 
	// Interpolation Factor = 4, DAC data format = 2's complement
	// NOTE:  Uncomment the following line if executing the demonstrational FFT processing.
	 temp = Write_Byte_to_AD9866(0xC, 0x81);	
}



/* Exception handler */
EX_EXCEPTION_HANDLER(ex_handler)
{
	while(1){
// blink LEDs
		int i =0;
		for (i = 0; i<1000000; i++) {asm("nop;");};
		*((short *)FIO_FLAG_S) = 0x000F;
		for (i = 0; i<1000000; i++) {asm("nop;");};
		*((short *)FIO_FLAG_C) = 0x000F;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -