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

📄 main.c

📁 此为ADSP_BF533_EZ_KIT中AD924作AD用时的驱动程序
💻 C
字号:
/*****************************************************************************************/
//
// Name: 	BF533 EZ-KIT interface to the AD9244 ADC Evaluation Board 
//
/*****************************************************************************************

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

File Name:				Main.c

Date Modified:			06/06/03		KU		Rev 1.0

Software:       		VisualDSP++3.1

Hardware:				BF533 EZ-KIT Board	Rev 1.1
						Extender Card	Rev. 1.3
						AD9244 Evaluation Board

Hardware Setup:			Boards:
							Connect the Expander Board to the EZ-KIT 
							Connect the AD9244 Evaluation board to the Expander Board via the HSC connector (J3)
                        Settings of the switches on the Expander Board:
						 	SW1 :	1	OFF
									2	ON
									3	OFF
									4	OFF
									5	OFF
									6	OFF
						
							SW2 :	1	OFF			(ON for rev0.0 of ADSP-BF533 silicon ONLY)
									2	OFF			(ON for rev0.0 of ADSP-BF533 silicon ONLY)
									3	OFF
									4	OFF
									5	ON
									6	OFF
						Settings of the switches on the EZ-Kit:
                        		default settings
                        ADC clock source:
                           			there are several ways to provide a clock to the ADC. Please refer to the 
                           			documentation for the AD9244. In this example, a 32MHz oscillator was 
                           			inserted into socket U7 of the Expander board and the resulting clock signal 
                           			on Pin 1 of connector J3 was brought to the CLKIN SMA connector of the AD9244 board.
                           			

ADC clock requirements:
						The ADC clock frequency must be smaller the SCLK/2. You can change SCLK by writing to the PLLDIV register.


DATA formats:
						The data received over the PPI interface is LEFT aligned, signed (1.15 format). The lower bits are
						to be ignored.
						Make sure that the ADC outputs data in two's complement format. On the AD9244, this is achieved by closing JP2.
						
						
Purpose:				Read in continous streams of data from the ADC. The data is read into a memory buffer ("sPPI_RxBuffer") 
						via the PPI	interface of the ADSP-BF533. A double buffering scheme is implemented so that data in one 
						half is available for processing while the other half is being filled with new data via DMA operations.
						A flag ("Ping_Pong") indicates which half is ready for processing.
						In this example, the main loop just copies the data that is ready into another buffer ("ADC_data") 
						(only for demonstration puroposes, you may display [plot menu] the data in VisualDSP from this buffer)
						
						
******************************************************************************************/


#include "system.h"
#include "sysreg.h"
#include "ccblkfn.h"

int initFlags();

// Declare Exception Handler
EX_EXCEPTION_HANDLER(ex_handler);


// GLOBAL vectors


// Declare the DMA input buffer
volatile short sPPI_RxBuffer[Number_of_ADC_channels * Number_of_Samples * 2];

// Declare the Pointers to beginning of each Channel Frame
// each points to the beginning of the channel frame in sPPI_RxBuffer (the first half)
// beginning of second half = ADCC_channel_ptrs_begin + Number_of_ADC_channels * Number_of_Samples
short *ADC_channel_ptrs_begin[Number_of_ADC_channels];


// set up DMA descriptors (sequence = 1st half, then second half, then repeat)
// small descriptor model, only start address needs to be fetched
tDMA_descriptor DMA_RX_second; // declaration
section("L1_data_a") tDMA_descriptor DMA_RX_first = {&DMA_RX_second, sPPI_RxBuffer};
section("L1_data_a") tDMA_descriptor DMA_RX_second = {&DMA_RX_first, (sPPI_RxBuffer + sizeof(sPPI_RxBuffer)/sizeof(sPPI_RxBuffer[0])/2)};


// copy-buffer for display
volatile short ADC_data[Number_of_ADC_channels * Number_of_Samples * 2];



// 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 Ping_Pong = 0;			// 0 = first half, 1 = second half

// semaphore to indicate that a half has been transmitted 
short DMA_completed_Receive = 0;

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


/*****************************************************************************************
 USER CODE
******************************************************************************************/
 
section("L1_code") void main() {
	int i = 0;

	sysreg_write(reg_SYSCFG, 0x32);		//Initialize System Configuration Register
		
	*((short *)PLL_DIV) = 3;
	
	// init exception handler
	register_handler(ik_exception,ex_handler);

	// initialise SDRAM controller	
	InitSDRAM();

// Routes the ADC clock to the PPI interface
// MUX's U25 and U26 on the EZ-KIT are set through writes to the IO port of the Flash Memory U5
// This is not required if hardware other than the EZ-Kit is used
#ifdef EZ_KIT
	InitFlash();
#endif
	

	// Reset the DMA semaphores
	Ping_Pong = 0;
	DMA_completed_Receive = 0;

	
	//clear receive buffer
	for(i=0; i<Number_of_ADC_channels * Number_of_Samples * 2; i++) {
		sPPI_RxBuffer[i] = 0;
	}
	
 	// configure the programmable flags (for debug)
	initFlags();
	
	// initialise Hardware
	InitPPI();					// enable PPI (will start only after an impulse on PF2)
	InitInterrupts();

	
/*	The following creates a short pulse to start the PPI acquisition. Note that this is on;y required for rev 0.0 of silicon since 
	the self-start mode was not implemented. For all higher revs, ignore this.
	
	// create a short impulse on PF2 to kick off the PPI (only needed until self-initiating mode is implemented in silicon)
	// make this un-interruptible
	asm("cli %0;" : "=d" (interruptLatch)); asm("ssync;");
	  	*pFIO_FLAG_S = (0x0004);
		asm("ssync;");
		for (i=0; i<100; i++) asm("nop;");	// small wait
		*pFIO_FLAG_C = (0x0004);
		asm("ssync;");
	asm("sti %0;" : : "d" (interruptLatch)); asm("ssync;");
*/




// MAIN loop
	// waits indefinetely for interrupts from DMA
	// When an interrupt has occured, the flag indicates which half of the received data the main loop can process 
	while(1) {

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

		asm("sti %0;" : : "d" (interruptLatch)); asm("ssync;");

		// insert interruptible code here
		//	variable Ping_Pong indicates which half is "free"
		// for instance: copy to buffer for display

		*pFIO_FLAG_S = 0x0001;						// PF0 shows execution time of this loop
		for (i=(Ping_Pong * Number_of_ADC_channels * Number_of_Samples); i<(((Ping_Pong+1) * Number_of_ADC_channels * Number_of_Samples)); i++) 
			ADC_data[i] = sPPI_RxBuffer[i];
		*pFIO_FLAG_C = 0x0001;						// PF0 shows execution time of this loop
		
		
	}			// while (1)

}				// main


int initFlags() {
	// Configure the flags 0-15 as inputs, exceptPF2and0
	*((short *)FIO_DIR) = *((short *)FIO_DIR) & (0x0005);
	*((short *)FIO_DIR) = *((short *)FIO_DIR) | (0x0005);
	
	// Deassert the output flags
  	*pFIO_FLAG_C = (0x0005);
	asm("ssync;");
	return 0;
}



// Exception handler
// do nothing, just stall
EX_EXCEPTION_HANDLER(ex_handler)
{
	while(1);
}

⌨️ 快捷键说明

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