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

📄 main.c

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

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

File Name:				Main.c

Date Modified:			06/05/03		KU		Rev 1.0

Software:       		VisualDSP++3.1

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

Hardware Setup:			Boards:
							Connect the Expander Board to the EZ-KIT 
							Connect the AD9744 Evaluation board to the Expander Board via the HSC connector (J4). Use the provided ribbon cable
                        Settings of the switches on the Expander Board:
							SW1 :	1	OFF
									2	OFF
									3	OFF
									4	OFF
									5	OFF
									6	OFF

							SW2 :	1	OFF
									2	OFF
									3	OFF
									4	OFF
									5	OFF
									6	ON
							
						Settings of the switches on the EZ-Kit:
                        		default settings
                        DAC clock source:
                           			there are several ways to provide a clock to the DAC. Please refer to the 
                           			documentation for the AD9744. In this example, a 32MHz oscillator was 
                           			inserted into socket U7 of the Expander board and the resulting clock signal 
                           			on Pin 33 of connector J4 is the clock input for the AD9744 board.
                           			
DAC clock requirements:
						The DAC clock frequency must be smaller the SCLK/2. You can change SCLK by writing to the PLLDIV register if required.
						The default setting for the EX-Kit rev1.1. board is SCLK = 54MHz.  For this example, SCLK has been changed to 90MHz by 
						setting PLLDIV to 3.

DATA formats:
						The data transmitted over the PPI interface is LEFT aligned, signed (1.15 format). The lower bits are ignored 
						by the DAC.
						
Purpose:				Writes continous streams of data to the DAC. The data is transmitted from a memory buffer ("sPPI_TxBuffer") 
						via the PPI	interface of the ADSP-BF533. A double buffering scheme is implemented so that data in one 
						half is available for "re-fill" while the other half is being transmitted out via DMA operations.
						A flag ("Ping_Pong") indicates which half is available for the new data.
						A variety of predefined output signals are #defined in system.h. In the case of SINES being defined, you may 
						also define amplitude and frequency. The sinevalues are then precalculated.
						You may insert your own code into the interruptible portion of the main loop. The execution time of this 
						additional code must be smaller then the period of DMA interrupts, i.e. the time for transmitting 
						one half of the buffer.
						
******************************************************************************************/


#include "system.h"
#include <math.h>
#include "sysreg.h"
#include "ccblkfn.h"

int initFlags();

// Declare Exception Handler
EX_EXCEPTION_HANDLER(ex_handler);


// GLOBAL vectors

// Declare the DMA output buffer
volatile short sPPI_TxBuffer[Number_of_DAC_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_TxBuffer (the first half)
// beginning of second half = DAC_channel_ptrs_begin + Number_of_DAC_channels * Number_of_Samples
short *DAC_channel_ptrs_begin[Number_of_DAC_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_TX_second; // declaration
section("L1_data_a") tDMA_descriptor DMA_TX_first = {&DMA_TX_second, sPPI_TxBuffer};
section("L1_data_a") tDMA_descriptor DMA_TX_second = {&DMA_TX_first, (sPPI_TxBuffer + sizeof(sPPI_TxBuffer)/sizeof(sPPI_TxBuffer[0])/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 indicated that a half has been transmitted 
short DMA_completed_Transmission = 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
	
	//Change SCLK to be CCLK/3 = 90MHz.
	*((short *)PLL_DIV) = 3;
	
	// init exception handler
	register_handler(ik_exception,ex_handler);

	// initialise SDRAM controller	
	InitSDRAM();

// Routes the DAC 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_Transmission = 0;

	
	//initialise transmission buffer
	for(i=0; i<Number_of_DAC_channels * Number_of_Samples * 2; i++) {
		sPPI_TxBuffer[i] = 0;
#ifdef LINEAR
		sPPI_TxBuffer[i] = (i+1) * 16384 /(Number_of_DAC_channels * Number_of_Samples);
#else
	#ifdef SINES
		sPPI_TxBuffer[i] = (signed short)(AMPLITUDE * sin((FREQ_RATIO)*6.283*i/Number_of_Samples));
	#endif
#endif
	}
	
 	// configure the programmable flags
	initFlags();
	
	// initialise Hardware (the order is important!!)
	InitPPI_Timer();
	InitPPI();
	InitInterrupts();
	StartPPI();					// really only enables the timer to generate the frame syncs

	
	// MAIN loop
	// waits indefinetely for interrupts from DMA
	// When an interrupt has occured, the flag indicated which half the main loop can put data into
	while(1) {

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

		// insert interruptible code here
		//	variable Ping_Pong indicates which half is "free" and can be filled with new data

		
	}			// while(1)

}				// main


int initFlags() {
	// Configure the flags 4-15 as outputs
	*((short *)FIO_DIR) = *((short *)FIO_DIR) & (0xFFF0);
	*((short *)FIO_DIR) = *((short *)FIO_DIR) | (0xFFF0);
	
	// Deassert the output flags
  	*pFIO_FLAG_C = (0xFFF0);
	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 + -