#include "xaxivdma.h"
#include "xaxivdma_i.h"
#include "xhls_sobel.h"
#include "sleep.h"
#include"xparameters.h" #define DISPLAY_VDMA XPAR_AXI_VDMA_0_BASEADDR + 0 //VDMA0在DDR中的映射
#define SOBEL_VDMA XPAR_AXI_VDMA_1_BASEADDR + 0 //VDMA1在DDR中的映射
#define DIS_X 1280 //显示区域的行、场信号,设置显示屏的大小
#define DIS_Y 720
#define SOBEL_ROW 512 //图片显示区域的大小
#define SOBEL_COL 512 #define SOBEL_S2MM 0x08000000 //sobel处理ip的接收数据的存储地址
#define SOBEL_MM2S 0x0A000000 //sobel处理ip的处理完毕之后发送数据的存储地址
#define DISPLAY_MM2S 0x0C000000 //仅可读取的VDVA的数据发送地址 u32 *BufferPtr[]; //定义一个32位无符号的缓存指针
static XHls_sobel sobel; //定义一个sobel结构体 //函数声明,该函数用于将数据刷入DDR
void Xil_DCacheFlush(void);
// 所有数据格式 为 AGBR,低位的透明度暂不起作用
extern const unsigned char gImage_lena[];

/*
下面函数的作用是对控制sobel的数据来源与去向的VDMA进行操作配置,其流程为
1、将VDMA控制器复位,延时,然后进行锁定
2、设置数据到DDR三帧缓存的地址0,4,8
3、设置显示图片的的行宽度,datasheet中说该信号indicate the horizontal size in bytes,一个像素点为4bytes
4、设置显示图片的的高,indicate verical size in lines of the data to transfer
然后同理设置从VDMA发送数据到SOBEL进行处理的图像数据帧缓存
*/
void SOBEL_VDMA_setting(unsigned int width,unsigned int height,unsigned int s2mm_addr,unsigned int mm2s_addr)
{
//S2MM
Xil_Out32(SOBEL_VDMA + 0x30, 0x4); //reset S2MM VDMA Control Register
usleep();
Xil_Out32(SOBEL_VDMA + 0x30, 0x0); //genlock
Xil_Out32(SOBEL_VDMA + 0xAC, s2mm_addr);//S2MM Start Addresses
Xil_Out32(SOBEL_VDMA + 0xAC+, s2mm_addr);
Xil_Out32(SOBEL_VDMA + 0xAC+, s2mm_addr);
Xil_Out32(SOBEL_VDMA + 0xA4, width*);//S2MM Horizontal Size
Xil_Out32(SOBEL_VDMA + 0xA0, height);//S2MM Vertical Size start an S2M
Xil_Out32(SOBEL_VDMA + 0xA8, width*);//S2MM Frame Delay and Stride
Xil_Out32(SOBEL_VDMA + 0x30, 0x3);//S2MM VDMA Control Register
// Xil_DCacheFlush(); //MM2S
Xil_Out32(SOBEL_VDMA + 0x00,0x00000003); // enable circular mode
Xil_Out32(SOBEL_VDMA + 0x5c,mm2s_addr); // start address
Xil_Out32(SOBEL_VDMA + 0x60,mm2s_addr); // start address
Xil_Out32(SOBEL_VDMA + 0x64,mm2s_addr); // start address
Xil_Out32(SOBEL_VDMA + 0x58,(width*)); // h offset
Xil_Out32(SOBEL_VDMA + 0x54,(width*)); // h size
Xil_Out32(SOBEL_VDMA + 0x50,height); // v size
//Xil_DCacheFlush();
}
/*
本函数仅用于将数据发送到视频数据流处理模块,流程为:
1、设置成循环显示模式,然后设置三帧数据缓存的起始地址
*/
void DISPLAY_VDMA_setting(unsigned int width,unsigned height,unsigned int mm2s_addr)
{
Xil_Out32((DISPLAY_VDMA + 0x000), 0x00000003); // enable circular mode
Xil_Out32((DISPLAY_VDMA + 0x05c), mm2s_addr); // start address
Xil_Out32((DISPLAY_VDMA + 0x060), mm2s_addr); // start address
Xil_Out32((DISPLAY_VDMA + 0x064), mm2s_addr); // start address
Xil_Out32((DISPLAY_VDMA + 0x058), (width*)); // h offset (640 * 4) bytes
Xil_Out32((DISPLAY_VDMA + 0x054), (width*)); // h size (640 * 4) bytes
Xil_Out32((DISPLAY_VDMA + 0x050), height); // v size (480)
}
/*
sobel数据输入处理部分,ADDr是MM2S即数据从DDR到VDMA的数据通道,将数据写入对应位置后,将数据刷入DDR,
刷入的位置是将将数据发送到MM2S的起始位置
*/
void SOBEL_DDRWR(unsigned int addr,unsigned int cols,unsigned int rows)
{
u32 i=;
u32 j=;
u32 r,g,b;
for(i=;i<cols;i++)
{
for(j=;j<rows;j++)
{
b= gImage_lena[(j+i*cols)*+]; //B-G-R
g= gImage_lena[(j+i*cols)*+];
r= gImage_lena[(j+i*cols)*+];
Xil_Out32((addr+(j+i*cols)*),((r<<)|(g<<)|(b<<)|0x0));
}
}
Xil_DCacheFlush();
}
/*
sobel IP核的设置
1、设置处理图片的宽和高,然后禁止自启动模式,禁用中断,
2、设置数据配套VDMA,然后将数据输入DDR
3、启动Sobel ip核
*/
void SOBEL_Setup()
{
//const int cols = 512;
//const int rows = 512;
XHls_sobel_SetRows(&sobel, SOBEL_COL);
XHls_sobel_SetCols(&sobel, SOBEL_ROW);
XHls_sobel_DisableAutoRestart(&sobel);
XHls_sobel_InterruptGlobalDisable(&sobel);
SOBEL_VDMA_setting(SOBEL_ROW,SOBEL_COL,SOBEL_S2MM,SOBEL_MM2S);
SOBEL_DDRWR(SOBEL_MM2S,SOBEL_ROW,SOBEL_COL);
//init_hls_sobel_dma(cols,rows, VIDEO_BASEADDR, HLS_VDMA_MM2S_ADDR);
//DDRVideoWr(HLS_VDMA_MM2S_ADDR, cols,rows);
XHls_sobel_Start(&sobel);
}
//设置显示屏背景色为全黑RGB=000
void Set_blackground(u32 size_x,u32 size_y,u32 disp_addr)
{
u32 i=;
u32 j=;
//u32 r,g,b;
for(j=;j<size_y;j++)
{
for(i=;i<size_x;i++)
{
Xil_Out32((disp_addr+(i+j*size_x)*),); //black
}
}
Xil_DCacheFlush();
}
/*
图片显示,
显示两张,一张是原始图片,另一张是出力轴的图片,两张根据type进行区别,将显示数据从addr中读出,然后将数据写入到显示区域,最后将数据刷入DDR
*/
void show_img(u32 x, u32 y, u32 disp_base_addr, const unsigned char * addr, u32 size_x, u32 size_y,u32 type)
{
//计算图片 左上角坐标
u32 i=;
u32 j=;
u32 r,g,b;
u32 start_addr=disp_base_addr;
start_addr = disp_base_addr + *x + y**DIS_X;
for(j=;j<size_y;j++)
{
for(i=;i<size_x;i++)
{
if(type==)
{
b = *(addr+(i+j*size_x)*+); //
g = *(addr+(i+j*size_x)*+); //
r = *(addr+(i+j*size_x)*); //
}
else
{
b = *(addr+(i+j*size_x)*+); //
g = *(addr+(i+j*size_x)*+); //
r = *(addr+(i+j*size_x)*+); //
}
Xil_Out32((start_addr+(i+j*DIS_X)*),((r<<)|(g<<)|(b<<)|0x0));
}
}
Xil_DCacheFlush();
} int main(void)
{ //Xil_DCacheFlush();
xil_printf("Starting the first VDMA \n\r");
int status = XHls_sobel_Initialize(&sobel, XPAR_HLS_SOBEL_0_S_AXI_CONTROL_BUS_BASEADDR);
if( != status)
{
xil_printf("XHls_Sobel_Initialize failed \n");
}
SOBEL_Setup();
DISPLAY_VDMA_setting(DIS_X,DIS_Y,DISPLAY_MM2S);
Set_blackground(,,DISPLAY_MM2S); /******************************
for(i=0;i<614400;i++)
{
Xil_Out32(VIDEO_BASEADDR0+i,0);
}
*******************************/
while()
{
//show_img(0,0,VIDEO_BASEADDR0,&gImage_beauty[0],563,600);
//sleep(5);
//show_img(0,0,VIDEO_BASEADDR0,&gImage_miz702_rgba[0],375,400);
//sleep(5);
show_img(,,DISPLAY_MM2S,(void*)SOBEL_S2MM,,,);
show_img(,,DISPLAY_MM2S,(void*)SOBEL_MM2S,,,);
}
return ;
}

首先包含几个头文件,#include "xaxivdma.h"用于服务可读写操作的VDMA1,#include "xaxivdma_i.h"用于服务仅可读取的VDMA0,sleep.h用于延时服务,#include"xparameters.h"用于包含硬件IP的各种映射信息

Sobel硬件实现的硬件代码分析(三)的更多相关文章

  1. android4.0 的图库Gallery2代码分析(三) 之Applition的初始化准备

    Applition的初始化准备 图库的一切动作都明显地起源于Application.这是区别与其他那种感觉不到Application存在,仅仅感觉到Activity存在的简单应用的一个特点. 图库的a ...

  2. Android4.0图库Gallery2代码分析(二) 数据管理和数据加载

    Android4.0图库Gallery2代码分析(二) 数据管理和数据加载 2012-09-07 11:19 8152人阅读 评论(12) 收藏 举报 代码分析android相册优化工作 Androi ...

  3. ADB结构及代码分析【转】

    本文转载自:http://blog.csdn.net/happylifer/article/details/7682563 最近因为需要,看了下adb的源代码,感觉这个作者很牛,设计的很好,于是稍微做 ...

  4. Device Tree(三):代码分析【转】

    转自:http://www.wowotech.net/linux_kenrel/dt-code-analysis.html Device Tree(三):代码分析 作者:linuxer 发布于:201 ...

  5. Device Tree(三):代码分析

    一.前言 Device Tree总共有三篇,分别是: 1.为何要引入Device Tree,这个机制是用来解决什么问题的?(请参考引入Device Tree的原因) 2.Device Tree的基础概 ...

  6. 【转】Device Tree(三):代码分析

    原文网址:http://www.wowotech.net/linux_kenrel/dt-code-analysis.html 一.前言 Device Tree总共有三篇,分别是: 1.为何要引入De ...

  7. 微信小游戏 demo 飞机大战 代码分析 (三)(spirit.js, animation.js)

    微信小游戏 demo 飞机大战 代码分析(三)(spirit.js, animation.js) 微信小游戏 demo 飞机大战 代码分析(一)(main.js) 微信小游戏 demo 飞机大战 代码 ...

  8. WebShell代码分析溯源(三)

    WebShell代码分析溯源(三) 一.一句话变形马样本 <?php $g = array('','s');$gg = a.$g[1].ser.chr('116');@$gg($_POST[ge ...

  9. 虚拟机创建流程中neutron代码分析(三)

    前言: 当neutron-server创建了port信息,将port信息写入数据库中.流程返回到nova服务端,接着nova创建的流程继续走.在计算节点中neutron-agent同样要完成很多的工作 ...

  10. C#代码分析(第三周)

    阅读下面程序,请回答如下问题: 问题1:这个程序要找的是符合什么条件的数? 问题2:这样的数存在么?符合这一条件的最小的数是什么? 问题3:在电脑上运行这一程序,你估计多长时间才能输出第一个结果?时间 ...

随机推荐

  1. [UVa1057] Routing

    问题描述 As more and more transactions between companies and people are being carried out electronically ...

  2. Element ui 中的Upload用法

    效果图: 代码:

  3. 随机森林(Random Forest,简称RF)和Bagging算法

    随机森林(Random Forest,简称RF) 随机森林就是通过集成学习的思想将多棵树集成的一种算法,它的基本单元是决策树,而它的本质属于机器学习的一大分支——集成学习(Ensemble Learn ...

  4. Kohana重写接收不到get参数问题

    .htaccess,不需要重启apache # Turn on URL rewriting RewriteEngine On # Installation directory RewriteBase ...

  5. Angular项目 Error: [ngRepeat:dupes] Duplicates in a repeater are not allowed.报错

    在angular的项目里,一不小心就会出现这个错误[ngRepeat:dupes] ,这个问题是因为内容有重复引起的解决起来挺简单 在对应的ng-repeat指令中增加track by $index, ...

  6. SpringCloud 教程 (二) 服务链路追踪(Spring Cloud Sleuth)

    一.简介 Add sleuth to the classpath of a Spring Boot application (see below for Maven and Gradle exampl ...

  7. 《SQL Server 2012 T-SQL基础》读书笔记 - 3.联接查询

    Chapter 3 Joins Cross Joins(交叉联接)就是返回两个表的笛卡尔积(m行的表cross join一个n行的表得到一个m * n行的结果),它有两种标准SQL语法,第一种: SE ...

  8. kubernetes-traefik(二十一)

    参考文档:http://traefik.cn/ traefik和ingress的对比 ingress: 使用nginx作为前端负载均衡,通过ingress controller不断的和kubernet ...

  9. C/C++判断字符串是否包含某个子字符串

    C风格 #include <iostream> #include <string> #include <cstring> using namespace std; ...

  10. 10.6 Comment Syntax

    w https://dev.mysql.com/doc/refman/5.7/en/comments.html MySQL 5.7 Reference Manual  /  Language Stru ...