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

📄 memorydma.c

📁 blackfin处理器系统代码,对dma,中断,标志位的设置都有很大的帮助.
💻 C
字号:
/*********************************************************************************

Copyright(c) 2005 Analog Devices, Inc. All Rights Reserved. 

This software is proprietary and confidential.  By using this software you agree
to the terms of the associated Analog Devices License Agreement.  
			
*********************************************************************************/


/*********************************************************************

Include files

*********************************************************************/

#include <services/services.h>		// system service includes




/*********************************************************************

Function prototypes

*********************************************************************/

static void InitSystemServices(void);                            // system services initialization
static void Callback(void *ClientHandle, u32 Event, void *pArg); // callback function



/*********************************************************************

Global data

*********************************************************************/

static ADI_DMA_MANAGER_HANDLE DMAManagerHandle;  // handle to the DMA manager
static ADI_DMA_STREAM_HANDLE  StreamHandle;      // handle to the memory stream

#define DATA_SIZE (32)       // size of the data
static u8 Src[DATA_SIZE];    // source data
static u8 Dest[DATA_SIZE];   // destination data



/*********************************************************************

	Function:		main

	Description:	Creates a callback when button 1 on the EZ-Kit
	                is pressed.  
	                
	                Flag mappings on the BF537 EZ-Kit:
	                     Buttons 1 thru 4 correspond to PF2 thru PF5
	                     LEDs 6 thru 10 correspond to PF6 thru PF11

*********************************************************************/

void main()	
{

	u32 i;
	ADI_DMA_RESULT Result;
		
	// initialize system services
	InitSystemServices();

	// populate the data
	for (i = 0; i < DATA_SIZE; i++) {
		Src[i] = i;
	}
	
	// open the stream, parameters are
	//      DMA manager handle
	//      memory stream ID
	//      client handle
	//      address of location where stream handle will be stored
	//      deferred callback handle (NULL = live callbacks)
	Result = adi_dma_MemoryOpen(DMAManagerHandle,
								ADI_DMA_MDMA_0, 
								(void *)0x12345678, 
								&StreamHandle, 
								NULL);
	
	// use DMA to copy the data, parameters are
	//      handle to stream, 
	//      destination address, 
	//      source address, 
	//      element width, 
	//      # bytes to transfer
	//      callback function
	Result = adi_dma_MemoryCopy(StreamHandle, 
								Dest, 
								Src, 
								1, 
								DATA_SIZE, 
								Callback);
	
	// spin
	for (i = 0; 1; i) {
		i++;
	}
}






/*********************************************************************

	Function:		Callback

	Description:	Called when the DMA completes
						ClientHandle - 0x12345678
						Event - eventID that occured
						pArg - event specific info

*********************************************************************/

void static Callback(void *ClientHandle, u32 Event, void *pArg){

    ADI_DMA_RESULT Result;
    
    // IF (the transfer is complete) 
	if ((ADI_DMA_EVENT)Event == ADI_DMA_EVENT_DESCRIPTOR_PROCESSED) {
		
		// do another transfer, parameters are 
		//      handle to stream, 
		//      destination address, 
		//      source address, 
		//      element width, 
		//      # bytes to transfer
		//      callback function
		Result = adi_dma_MemoryCopy(StreamHandle, 
									Dest, 
									Src, 
									1, 
									DATA_SIZE, 
									Callback);
		
	// ENDIF
	}
		
}








/*********************************************************************

	Function:		InitSystemServices

	Description:	Initializes the necessary system services.  

*********************************************************************/

void InitSystemServices(void) {
    
    u32 i;
    u32 Result;

    ADI_EBIU_SDRAM_BANK_VALUE bank_size;
	ADI_EBIU_SDRAM_BANK_VALUE bank_width;
	u32                       cl_threshold = 100;                                        // set cl threshold to 100 Mhz
	ADI_EBIU_TIMING_VALUE     twrmin       = {1,{7500, ADI_EBIU_TIMING_UNIT_PICOSEC}};   // set min TWR to 1 SCLK cycle + 7.5ns	
	ADI_EBIU_TIMING_VALUE     refresh      = {8192,{64, ADI_EBIU_TIMING_UNIT_MILLISEC}}; // set refresh period to 8192 cycles in 64ms
	ADI_EBIU_TIME             trasmin      = {44, ADI_EBIU_TIMING_UNIT_NANOSEC};         // set min TRAS to 44ns
	ADI_EBIU_TIME             trpmin       = {20, ADI_EBIU_TIMING_UNIT_NANOSEC};	     // set min TRP to 20ns
	ADI_EBIU_TIME             trcdmin      = {20, ADI_EBIU_TIMING_UNIT_NANOSEC}; 	     // set min TRCD to 20ns
	bank_size.value.size                   = ADI_EBIU_SDRAM_BANK_64MB; 	                 // set bank size to 64MB
	bank_width.value.width                 = ADI_EBIU_SDRAM_BANK_COL_10BIT;	             // set column address width to 10-Bit

	ADI_EBIU_COMMAND_PAIR ezkit_sdram[] = { 
		{ ADI_EBIU_CMD_SET_SDRAM_BANK_SIZE,     (void*)&bank_size   },
       	{ ADI_EBIU_CMD_SET_SDRAM_BANK_COL_WIDTH,(void*)&bank_width  },
       	{ ADI_EBIU_CMD_SET_SDRAM_CL_THRESHOLD,  (void*)cl_threshold },
      	{ ADI_EBIU_CMD_SET_SDRAM_TRASMIN,       (void*)&trasmin     }, 
       	{ ADI_EBIU_CMD_SET_SDRAM_TRPMIN,        (void*)&trpmin      }, 
       	{ ADI_EBIU_CMD_SET_SDRAM_TRCDMIN,       (void*)&trcdmin     }, 
       	{ ADI_EBIU_CMD_SET_SDRAM_TWRMIN,        (void*)&twrmin      },
       	{ ADI_EBIU_CMD_SET_SDRAM_REFRESH,       (void*)&refresh     },
      	{ ADI_EBIU_CMD_END,                     0                   }
	};

	ADI_PWR_COMMAND_PAIR ezkit_power[] = { 
    	{ ADI_PWR_CMD_SET_PROC_VARIANT,(void*)ADI_PWR_PROC_BF537SKBC1600 }, // 600Mhz ADSP-BF533 variant 
    	{ ADI_PWR_CMD_SET_PACKAGE,     (void*)ADI_PWR_PACKAGE_MBGA       }, // in MBGA packaging, as on all EZ-KITS
    	{ ADI_PWR_CMD_SET_VDDEXT,      (void*)ADI_PWR_VDDEXT_330         }, // external voltage supplied to the voltage regulator is 3.3V
    	{ ADI_PWR_CMD_SET_CLKIN,       (void*)ADI_PWR_CLKIN_EZKIT_BF537  },	// the CLKIN frequency 25 Hz
    	{ ADI_PWR_CMD_END,             0                                 } 
	}; 

	static u8 FlagServiceData[ADI_FLAG_CALLBACK_MEMORY *  1];	                    // memory for 1 callback
	static u8 DMAServiceData[ADI_DMA_BASE_MEMORY + (ADI_DMA_CHANNEL_MEMORY *  2)];	// memory for 2 channels

    // initialize the interrupt manager, parameters are
    //      pointer to memory for interrupt manager to use
    //      memory size (in bytes)
    //      location where the number of secondary handlers that can be supported will be stored
   	//      parameter for adi_int_EnterCriticalRegion (always NULL for VDK and standalone systems)
    Result = adi_int_Init(NULL, 
    					  0, 
    					  &i, 
    					  NULL);
    
	// initialize the EBIU, parameters are
	//      address of table containing SDRAM parameters
	//      0 - always 0 when EBIU initialized before power service
	Result = adi_ebiu_Init(ezkit_sdram,
						   0);
	
    // initialize power, parameters are
    //      address of table containing processor information
    Result = adi_pwr_Init( ezkit_power );

   	// initialize the flag manager, parameters are
   	//      pointer to memory for the flag service to use
   	//      memory size (in bytes)
   	//      location where the number of flags that can be supported will be stored
   	//      parameter for adi_int_EnterCriticalRegion (always NULL for VDK and standalone systems)
	Result = adi_flag_Init(FlagServiceData, 
	                       sizeof(FlagServiceData), 
	                       &i, 
	                       NULL);
	
   	// initialize the dma manager, parameters are
   	//      pointer to memory for the DMA manager to use
   	//      memory size (in bytes)
   	//      parameter for adi_int_EnterCriticalRegion (always NULL for VDK and standalone systems)
	Result = adi_dma_Init(DMAServiceData, 
	                      sizeof(DMAServiceData), 
	                      &i, 
	                      &DMAManagerHandle, 
	                      NULL);
	
}



⌨️ 快捷键说明

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