基于hi3531d的DMA操作


原文链接: 基于hi3531d的DMA操作

海思IVE函数使用1 (DMA使用 HI_MPI_IVE_DMA)
1 结构体定义

//灰度图像定义

typedef struct
{
    unsigned  char  *pu8Data;  //虚拟地址
    unsigned int  u32PhyAddr;   //物理地址
    int   s32Width;           //图像宽度
    int   s32Height;          //图像高度
    int  s32Stride;         //图像step 
}RV_GRAY_IMAGE_S;

//区域定义
typedef struct
{
    short left ;
    short top ;
    short right ;
    short bottom ;
}RV_RECT ;



2 IVE优化实现
---------

int RV_MEMCPY_IVE(RV_GRAY_IMAGE_S * pSrcImage, RV_GRAY_IMAGE_S * pDstImg,RV_RECT * pSrcRect,
                      RV_RECT * pDstRect)
{
    IVE_HANDLE hIveHandle = 0;
    HI_BOOL bInstant = HI_TRUE;
    HI_BOOL bBlock = HI_TRUE;
    HI_BOOL bFinish = HI_FALSE;
    HI_S32 result;
    int srcw = pSrcRect->right - pSrcRect->left + 1;
    int srch = pSrcRect->bottom - pSrcRect->top + 1;
    int dstw = pDstRect->right - pDstRect->left + 1;
    int dsth = pDstRect->bottom - pDstRect->top + 1;
   if (srcw != dstw || srch != dsth)
    {
        return -1;
    }

IVE_DATA_S stSrc = {  (HI_U32)(pSrcImage->u32PhyAddr + pSrcImage->s32Stride * pSrcRect->top + pSrcRect->left),
        pSrcImage->pu8Data+pSrcImage->s32Stride * pSrcRect->top + pSrcRect->left,
        pSrcImage->s32Stride, srcw, srch};

IVE_DATA_S stDst = { pDstImg->u32PhyAddr + pDstImg->s32Stride*pDstRect->top+pDstRect->left, 
        pDstImg->pu8Data + pDstImg->s32Stride*pDstRect->top+pDstRect->left, pDstImg->s32Stride, srcw,srch};

    IVE_DMA_CTRL_S stDmaCtrl = { IVE_DMA_MODE_DIRECT_COPY, 0};
    result = HI_MPI_IVE_DMA( &hIveHandle, &stSrc,&stDst, &stDmaCtrl,bInstant);
    if( result != HI_SUCCESS )
    {
        printf( "hi ive dma error=%x \n" ,result);
        return RV_ERROR ;
    }
    result = HI_MPI_IVE_Query(hIveHandle,&bFinish,bBlock);
    if(result != HI_SUCCESS)
    {
        //  printf("hi query dma  error \n"); //windows 模拟库都返回失败。这里不打印 
        //  return RV_ERROR ;    //无意外情况都是成功
    }
    else
    {
        if(bFinish != HI_TRUE)
        {
            printf("hi dma is not finished \n");
            return RV_ERROR ;
        }
    }
    return RV_SUCESS;
}

————————————————
版权声明:本文为CSDN博主「wfknife」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/wfknife/article/details/75174854

基于hi3531d的DMA操作

#include <fcntl.h>
#include "sample_comm.h"
#include "sample_comm_ivs.h"
 
 
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
char  *g_buffVirAddr;
#define g_BuffPhyAddr 0x81000000
int   buff_fd = -1;
int  buffer_mmap(unsigned int len)
{ 
        int i=0;
        
        buff_fd = open ("/dev/mem", O_RDWR);
        if (buff_fd < 0)
        {
             printf("cannot open /dev/mem.");
             return -1;
        }
        g_buffVirAddr = (char *)mmap(0, len, PROT_READ|PROT_WRITE, MAP_SHARED, buff_fd, g_BuffPhyAddr);   
        if(g_buffVirAddr<0)
        {
            printf("g_buffVirAddr mmap error!\n");
            close(buff_fd);
            return -1;
        }
 
        for(i=0;i<len;i++)
            *(unsigned char *)(g_buffVirAddr+i) = 0;//i%256;
 
        return 0;
}
 
 
 
 IVE_SRC_DATA_S stSrc;
    IVE_DST_DATA_S stDst;
    //IVE_DMA_CTRL_S stDmaCtrl;
    IVE_DMA_CTRL_S stDmaCtrl = { IVE_DMA_MODE_DIRECT_COPY, 0};
    HI_BOOL bInstant = HI_FALSE;
    IVE_HANDLE IveHandle;
    HI_BOOL bFinish, bBlock=HI_TRUE;
 
     
    //DMA init
    SAMPLE_COMM_IVE_CheckIveMpiInit();
    mem_addr(&buffer_x, phy_addr_x);
    mem_addr(&buffer_y, phy_addr_y);
	stSrc.u32PhyAddr = phy_addr_x;
	stSrc.pu8VirAddr = buffer_x;
	stSrc.u16Stride = 1024;
	stSrc.u16Height = 1024;    
	stSrc.u16Width = 1024;
 
	stDst.u32PhyAddr = phy_addr_y;
	stDst.pu8VirAddr = buffer_y;
	stDst.u16Stride = 1024;
	stDst.u16Height = 1024;
	stDst.u16Width = 1024;
	bInstant = HI_TRUE;
 
  for(i=0;i<stSrc.u16Height * stSrc.u16Stride;i++)
       buffer_x[i] = i%256;
 
	memset(buffer_y,0, stDst.u16Height * stDst.u16Stride);
 
 
/////////////////////////////////////////////////////////
	s32Ret = HI_MPI_IVE_DMA(&IveHandle, &stSrc, &stDst, &stDmaCtrl, bInstant);
	if(HI_SUCCESS!=s32Ret)
	{
		printf("IVE DMA error!\n");
		return s32Ret;
	}
        s32Ret = HI_MPI_IVE_Query(IveHandle, &bFinish, bBlock);	
	while(HI_ERR_IVE_QUERY_TIMEOUT == s32Ret)
	{
		//usleep(100);					
		s32Ret = HI_MPI_IVE_Query(IveHandle,&bFinish,bBlock);	
	}
 }
#makefile文件,修改自sample_enc例子
# Hisilicon Hi35xx sample Makefile
 
include ../Makefile.param
#ifeq ($(SAMPLE_PARAM_FILE), )
#     SAMPLE_PARAM_FILE:=../Makefile.param
#     include $(SAMPLE_PARAM_FILE)
#endif
 
# target source
SRC  := $(wildcard *.c) 
OBJ  := $(SRC:%.c=%.o)
 
TARGET := $(OBJ:%.o=%)
.PHONY : clean all
 
 
CPPFLAGS   := $(shell $(PYLON_ROOT)/bin/pylon-config --cflags)
CXXFLAGS   := #e.g., CXXFLAGS=-g -O0 for debugging
LDFLAGS    := $(shell $(PYLON_ROOT)/bin/pylon-config --libs-rpath)
LDLIBS     := $(shell $(PYLON_ROOT)/bin/pylon-config --libs)
 
 
 
CC        :=arm-hisiv600-linux-gcc
LD         := $(CC)
all: $(TARGET)
 
MPI_LIBS := $(REL_LIB)/libmpi.a
MPI_LIBS += $(REL_LIB)/libhdmi.a
IVE_LIBS := $(REL_LIB)/libive.a
IVE_LIBS += $(REL_LIB)/libmd.a
 
 
$(TARGET):%:%.o $(COMM_OBJ)
	$(CC) $(CFLAGS)  $(CPPFLAGS) $(CXXFLAGS) $(LDFLAGS) -lpthread -lm -L. -ltest -o $@ $^ $(MPI_LIBS) $(AUDIO_LIBA)  $(JPEGD_LIBA) $(IVE_LIBS) $(LDLIBS)  -lstdc++
 
clean:
	@rm -f $(TARGET)
	@rm -f $(OBJ)
	@rm -f $(COMM_OBJ)
 
cleanstream:
	@rm -f *.h264
	@rm -f *.jpg
	@rm -f *.mjp

————————————————
版权声明:本文为CSDN博主「毛毛虫的爹」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/mao0514/article/details/84838384

`