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

📄 edma.c

📁 DSP编程
💻 C
字号:
#ifndef _EDMA_H_
#include "EDMA.h"
#endif

/*-------------------------------------------------------------------------
 * qdma_start() - used to start QDMA    
 * Description:  32位数据传送
 * Parameter: src      EDMA传送的源地址
 *            dst      EDMA传送的目的地址
 *            sum/dum  =1  源地址/目的地址连续递增
 *                     =0  源地址/目的地址固定不变  
 *            size     EDMA传送的element的个数                 
 *
 * Note: "size" is the transfered count of the element, 
 *        and the element is 4 byte, so it will transfer
 *        size*4 from src to dst. The src and dst address increment.
 *        The max size is (2^16-1) = 65535 = 64k
 *        Frame Synchronized 1D Transfer (FS=1)
 *-------------------------------------------------------------------------*/

void qdma_start(int src, int dst, int sum, int dum, int size)
{ 
	
  *(unsigned volatile int *)CIERL |= (1<<QDMA_TCC);
  
  *(unsigned volatile int *)QDMA_OPT = (QDMA_PRI<<PRI) + (sum<<SUM) + (dum<<DUM) + (1<<TCINT)  
                                     + ((QDMA_TCC%16)<<TCC) + ((QDMA_TCC/16)<<TCCM)+ (1<<FS);

  *(unsigned volatile int *)QDMA_SRC = src;
  *(unsigned volatile int *)QDMA_DST = dst;
  *(unsigned volatile int *)QDMA_IDX = 0x00000000; 

  *(unsigned volatile int *)QDMA_S_CNT = size;
}
  


/*
To configure the EDMA for any channel (or QDMA request) to interrupt the CPU:
1.	Set CIE n to '1' in the CIER (Channel interrupt enable register)
2.	Set TCINT to '1' in channel options
3.	Set Transfer Complete Code(TCC) to n in channel options
*/
//left up corner is (0,0)

// use qdma to trans 2d src to 1d dst, test ok 2002/9/13 by shiyan 
int qdma_2Dto1D_start(int src, int dst, int image_size_x, int image_size_y,
						int LU_x, int LU_y, int RD_x, int RD_y,
						unsigned char nbytePerPixel)
{ 
	if((RD_x - LU_x +1)*nbytePerPixel % 4 != 0 ||
		(RD_x -LU_x +1)*(RD_y - LU_y +1)*nbytePerPixel % 8 !=0)
		return 1;

	//transfer element is 32bits
  *(unsigned volatile int *)CIERL |= (1<<QDMA_TCC);
  
  *(unsigned volatile int *)QDMA_OPT = (QDMA_PRI<<PRI) + (1<<DS) + (1<<SUM) + (0<<DUM) + (1<<TCINT)  
                                      + ((QDMA_TCC%16)<<TCC) + ((QDMA_TCC/16)<<TCCM) + (1<<FS);

  *(unsigned volatile int *)QDMA_SRC = src + (LU_y * image_size_x + LU_x) * nbytePerPixel;;
  *(unsigned volatile int *)QDMA_DST = dst;

  *(unsigned volatile int *)QDMA_IDX = ((image_size_x - 1 - RD_x + LU_x) * nbytePerPixel) <<16; 
  
  *(unsigned volatile int *)QDMA_S_CNT = (RD_y - LU_y) << 16 
  									| ((RD_x - LU_x +1)*nbytePerPixel / 4);
  
  return 0;
}

/*-----------------------------------------------------------------------------------------*/
int edma_start(int src, int dst, unsigned int ch, int sum, int dum, int islink, int size)
{ 
//	EDMA_REG *edma_reg = (EDMA_REG*)EVENT_PARAMS_ADDR(ch); 
	
	if((ch>=EDMA_CHANNEL_NUM)) 
      return 1;

  *(unsigned volatile int *)ECRL |= (1<<ch);		//clear 
    
  *(unsigned volatile int *)(EVENT_PARAMS_ADDR(ch) + OPT) = (EDMA_PRI<<PRI) + (sum<<SUM) + (dum<<DUM) + (1<<TCINT)  
                                                  + ((ch%16)<<TCC) + ((ch/16)<<TCCM) + (islink<<LINK) + (1<<FS);
 
  *(unsigned volatile int *)(EVENT_PARAMS_ADDR(ch) + SRC) = src;
  *(unsigned volatile int *)(EVENT_PARAMS_ADDR(ch) + DST) = dst;
  *(unsigned volatile int *)(EVENT_PARAMS_ADDR(ch) + IDX) = 0x00000000; 
   
  *(unsigned volatile int *)(EVENT_PARAMS_ADDR(ch) + CNT) = size;
  *(unsigned volatile int *)(EVENT_PARAMS_ADDR(ch) + LNK)= ((0xffff& NULL_PARAMS_ADDR));

  *(unsigned volatile int *)CIERL |= (1<<ch);	//enable channel interrupt
  *(unsigned volatile int *)EERL |= (1<<ch);	//enable EVENT

  return 0;
}

/*-----------------------------------------------------------------------------------------*/
int edma_1Dto2D_start(int src, int dst, unsigned int ch, int image_size_x, int image_size_y,
						int LU_x, int LU_y, int RD_x, int RD_y,
						unsigned char nbytePerPixel)
{ 
  if((RD_x - LU_x +1)*nbytePerPixel % 4 != 0 ||
	(RD_x -LU_x +1)*(RD_y - LU_y +1)*nbytePerPixel % 8 !=0)
      return 1;

  if((ch>=EDMA_CHANNEL_NUM)) 
      return 1;

  *(unsigned volatile int *)ECRL |= (1<<ch);		
    
  //transfer element is 32bits
  *(unsigned volatile int *)(EVENT_PARAMS_ADDR(ch) + OPT) = (EDMA_PRI<<PRI) + (1<<DD) + (1<<SUM) + (1<<DUM) + (1<<TCINT)
                                                        + ((ch%16)<<TCC) + ((ch/16)<<TCCM) + (1<<LINK) + (1<<FS);

  *(unsigned volatile int *)(EVENT_PARAMS_ADDR(ch) + SRC) = src;
  *(unsigned volatile int *)(EVENT_PARAMS_ADDR(ch) + DST) = dst + (LU_y * image_size_x + LU_x) * nbytePerPixel;

	//computer the parameter of the EDMA
  *(unsigned volatile int *)(EVENT_PARAMS_ADDR(ch) + IDX) = ((image_size_x - 1 - RD_x + LU_x) * nbytePerPixel) <<16;
  
  *(unsigned volatile int *)(EVENT_PARAMS_ADDR(ch) + CNT) = (RD_y - LU_y) << 16 
  											| ((RD_x - LU_x +1)*nbytePerPixel / 4);

  *(unsigned volatile int *)(EVENT_PARAMS_ADDR(ch) + LNK)= ((0xffff& NULL_PARAMS_ADDR));

  *(unsigned volatile int *)CIERL |= (1<<ch);
  *(unsigned volatile int *)EERL |= (1<<ch);

  return 0;
}

/*-----------------------------------------------------------------------------------------*/
int edma_2Dto1D_start(int src, int dst, unsigned int ch, int image_size_x, int image_size_y,
						int LU_x, int LU_y, int RD_x, int RD_y,
						unsigned char nbytePerPixel)
{ 
  if((RD_x - LU_x +1)*nbytePerPixel % 4 != 0 ||
	(RD_x -LU_x +1)*(RD_y - LU_y +1)*nbytePerPixel % 8 !=0)
      return 1;

  if((ch>=EDMA_CHANNEL_NUM)) 
      return 1;

  *(unsigned volatile int *)ECRL |= (1<<ch);		
    
  //transfer element is 32bits
  *(unsigned volatile int *)(EVENT_PARAMS_ADDR(ch) + OPT) = (EDMA_PRI<<PRI) + (1<<DS) + (1<<SUM) + (0<<DUM) + (1<<TCINT)
                                                        + ((ch%16)<<TCC) + ((ch/16)<<TCCM) + (1<<LINK) + (1<<FS);

  *(unsigned volatile int *)(EVENT_PARAMS_ADDR(ch) + SRC) = src + (LU_y * image_size_x + LU_x) * nbytePerPixel;;
  *(unsigned volatile int *)(EVENT_PARAMS_ADDR(ch) + DST) = dst;

	//computer the parameter of the EDMA
  *(unsigned volatile int *)(EVENT_PARAMS_ADDR(ch) + IDX) = ((image_size_x - 1 - RD_x + LU_x) * nbytePerPixel) <<16;
  
  *(unsigned volatile int *)(EVENT_PARAMS_ADDR(ch) + CNT) = (RD_y - LU_y) << 16 
  											| ((RD_x - LU_x +1)*nbytePerPixel / 4);

  *(unsigned volatile int *)(EVENT_PARAMS_ADDR(ch) + LNK)= ((0xffff& NULL_PARAMS_ADDR));

  *(unsigned volatile int *)CIERL |= (1<<ch);
  *(unsigned volatile int *)EERL |= (1<<ch);

  return 0;
}

/*----------------------------------------------------------------------------------------*/
void edma_null_init()
{ 

	*(unsigned volatile int *)(NULL_PARAMS_ADDR + OPT)= 0x0;
	*(unsigned volatile int *)(NULL_PARAMS_ADDR + SRC)= 0x0;
	*(unsigned volatile int *)(NULL_PARAMS_ADDR + CNT)= 0x0;
	*(unsigned volatile int *)(NULL_PARAMS_ADDR + DST)= 0x0;
	*(unsigned volatile int *)(NULL_PARAMS_ADDR + IDX)= 0x0;
	*(unsigned volatile int *)(NULL_PARAMS_ADDR + LNK)= 0x0;
}

⌨️ 快捷键说明

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