【iCore4 双核心板_FPGA】例程十六:基于双口RAM的ARM+FPGA数据存取实验

实验现象:

 

核心代码:

int main(void)
{/* USER CODE BEGIN 1 */int i;int address,data;char error_flag = 0;char receive_data[50];char buffer[8];char *p;/* USER CODE END 1 *//* MCU Configuration----------------------------------------------------------*//* Reset of all peripherals, Initializes the Flash interface and the Systick. */HAL_Init();/* USER CODE BEGIN Init *//* USER CODE END Init *//* Configure the system clock */SystemClock_Config();/* USER CODE BEGIN SysInit *//* USER CODE END SysInit *//* Initialize all configured peripherals */MX_GPIO_Init();MX_USART6_UART_Init();MX_FMC_Init();/* USER CODE BEGIN 2 */usart6.initialize(115200);usart6.printf("Hello, I am iCore4!\r\n");LED_GREEN_ON;/* USER CODE END 2 *//* Infinite loop *//* USER CODE BEGIN WHILE */while (1){/* USER CODE END WHILE *//* USER CODE BEGIN 3 */if(usart6.receive_ok_flag == 1){usart6.receive_ok_flag = 0;memset(receive_data,0,sizeof(receive_data));memset(buffer,0,sizeof(buffer));for(i = 0;i < 30;i ++){receive_data[i] = usart6.receive_buffer[i];}p = receive_data;i = 0;while(*p != ':'){                                    //»ñÈ¡²Ù×÷ÃüÁwrite or read£©buffer[i++] = *p++;if(i > sizeof(buffer))i = 0;}for(i = 0;i < sizeof(buffer);i++){//½«ÃüÁîת»¯ÎªÐ¡Ð´×Ö·ûbuffer[i] = tolower(buffer[i]);}if(memcmp(buffer,"read",strlen("read")) == 0){//Ö´ÐжÁ²Ù×÷error_flag = 0;p++;address = atoi(p);if(address > 255)error_flag = 1;p++;if(strchr(p,','))error_flag = 1;if(!error_flag){data = fpga_read(address);usart6.printf("Read FPGA Ram:%d\r\n",data);}                    }else{error_flag = 1;}if(error_flag){LED_RED_ON;LED_GREEN_OFF;usart6.printf("Bad Command!\r\n");}else{LED_RED_OFF;LED_GREEN_ON;}}}/* USER CODE END 3 */}
module dual_port_ram_ctrl(input clk_25m,input rst_n,input wrn,input rdn,input cs0,inout [15:0]db,input [23:16]ab,output led_red,output led_green,output led_blue
);//-----------------------------ram-----------------------------//
wire [15:0]dataout_a;
wire [15:0]dataout_b;ram u1(.data_a(data_a),.address_a(address_a),.wren_a(wren_a),.rden_a(rden_a),.clock_a(!clk_a),.q_a(dataout_a),.data_b(db),.address_b(ab),.wren_b(1'd0),.rden_b(!rd),.clock_b(clk_b),.q_b(dataout_b)
);//-----------------------------clk_100m-----------------------------//

pll u2(.inclk0(clk_25m),.c0(clk_100m)
);//-------------------------------clk_a-----------------------------//
reg clk1,clk2;
always@(posedge clk_100m or negedge rst_n)if(!rst_n)beginclk1 <= 1'd0;clk2 <= 1'd0;endelse {clk2,clk1} <= {clk1,clk_25m};wire clk_a = (clk_25m & clk1);//-------------------------------data-----------------------------//
reg [9:0]data;
always@(posedge clk_25m or negedge rst_n)if(!rst_n)data <= 10'd0;else if(data == 10'd511)data <= 10'd0;else data <= data + 1'd1;//-------------------------write & read port a-------------------//
reg wren_a;
reg rden_a;
reg [9:0]data_a;
reg [9:0]address_a;always@(posedge clk_a or negedge rst_n)if(!rst_n)beginwren_a <= 1'd0;rden_a <= 1'd0;data_a <= 10'd0;address_a <= 10'd0;endelse if(data >= 10'd0 && data <= 10'd255)beginwren_a <= 1'd1;rden_a <= 1'd0;data_a <= data;address_a <= data;endelse if(data >= 10'd256 && data <= 10'd511)beginwren_a <= 1'd0;rden_a <= 1'd1;address_a <= data - 10'd256;end//-----------------------------ram a---------------------------//
reg error;always@(negedge clk1 or negedge rst_n)if(!rst_n)error <= 1'd0;elsebeginif(wren_a || dataout_a == address_a)error <= 1'd0;elseerror <= 1'd1;end//--------------------------ram_a_led---------------------------//
reg ledr,ledg,ledb;
always@(posedge error or negedge rst_n)if(!rst_n)beginledr <= 1'd1;ledg <= 1'd0;ledb <= 1'd1;    endelsebeginledr <= 1'd0;ledg <= 1'd1;ledb <= 1'd1;            end    
assign {led_red,led_green,led_blue} = {ledr,ledg,ledb};//--------------------------ram_b_rd----------------------------//
wire rd = (cs0 | rdn);
wire wr = (cs0 | wrn);reg wr_clk1,wr_clk2;
always@(posedge clk_100m or negedge rst_n)if(!rst_n)beginwr_clk1 <= 1'd1;wr_clk2 <= 1'd1;endelse {wr_clk2,wr_clk1} <= {wr_clk1,wr};wire clk_b = (!wr_clk2 | !rd);
assign db = !rd ? dataout_b : 16'hzzzz;endmodule

源代码下载链接:

链接:http://pan.baidu.com/s/1qYqNlwg 密码:9il4

iCore4链接:

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/540566.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

laravel 项目迁移_在Laravel迁移

laravel 项目迁移Before moving forward we need to know some facts about it, 在继续前进之前&#xff0c;我们需要了解一些事实&#xff0c; Resources: In these directories, we have already a js, lang, sass and view page. Where, sass and js file holf their uncom…

[AtCoder-ARC073F]Many Moves

题目大意&#xff1a;   有一排n个格子和2枚硬币。   现在有q次任务&#xff0c;每一次要你把其中一枚硬币移到x的位置上&#xff0c;移动1格的代价是1。   两枚硬币不能同时移动&#xff0c;任务必须按次序完成。   现在告诉你两枚硬币初始状态所在的位置a和b&#xf…

OpenStack —— DevStack一键自动化安装

一、DevStack介绍Devstack目前是支持Ubuntu16.04和CentOS 7&#xff0c;而且Devstack官方建议使用Ubuntu16.04&#xff0c;所以我们使用Ubuntu 16.04进行安装。默认无论是Devstack和OpenStack&#xff0c;都是采用Master的代码进行安装&#xff0c;这样经常会出现&#xff0c;今…

Scala铸造

Scala中的类型 (Types in Scala) Type also know as data type tells the compiler about the type of data that is used by the programmer. For example, if we initialize a value or variable as an integer the compiler will free up 4 bytes of memory space and it wi…

OpenCV探索之路(二十五):制作简易的图像标注小工具

搞图像深度学习的童鞋一定碰过图像数据标注的东西&#xff0c;当我们训练网络时需要训练集数据&#xff0c;但在网上又没有找到自己想要的数据集&#xff0c;这时候就考虑自己制作自己的数据集了&#xff0c;这时就需要对图像进行标注。图像标注是件很枯燥又很费人力物力的一件…

图论 弦_混乱的弦

图论 弦Problem statement: 问题陈述&#xff1a; You are provided an input string S and the string "includehelp". You need to figure out all possible subsequences "includehelp" in the string S? Find out the number of ways in which the s…

「原创」从马云、马化腾、李彦宏的对话,看出三人智慧差在哪里?

在今年中国IT领袖峰会上&#xff0c;马云、马化腾、李彦宏第一次单独合影&#xff0c;同框画面可以说很难得了。BAT关心的走势一直是同行们竞相捕捉的热点&#xff0c;所以三位大Boss在这次大会上关于人工智能的见解&#xff0c;也受到广泛关注与多方解读。马云认为机器比人聪明…

字符串矩阵转换成长字符串_字符串矩阵

字符串矩阵转换成长字符串Description: 描述&#xff1a; In this article, we are going to see how backtracking can be used to solve following problems? 在本文中&#xff0c;我们将看到如何使用回溯来解决以下问题&#xff1f; Problem statement: 问题陈述&#xf…

java awt 按钮响应_Java AWT按钮

java awt 按钮响应The Button class is used to implement a GUI push button. It has a label and generates an event, whenever it is clicked. As mentioned in previous sections, it extends the Component class and implements the Accessible interface. Button类用于…

qgis在地图上画导航线_在Laravel中的航线

qgis在地图上画导航线For further process we need to know something about it, 为了进一步处理&#xff0c;我们需要了解一些有关它的信息&#xff0c; The route is a core part in Laravel because it maps the controller for sending a request which is automatically …

Logistic回归和SVM的异同

这个问题在最近面试的时候被问了几次&#xff0c;让谈一下Logistic回归&#xff08;以下简称LR&#xff09;和SVM的异同。由于之前没有对比分析过&#xff0c;而且不知道从哪个角度去分析&#xff0c;一时语塞&#xff0c;只能不知为不知。 现在对这二者做一个对比分析&#xf…

构建安全网络 比格云全系云产品30天内5折购

一年之计在于春&#xff0c;每年的三、四月&#xff0c;都是个人创业最佳的起步阶段&#xff0c;也是企业采购最火热的时期。为了降低用户的上云成本&#xff0c;让大家能无门槛享受到优质高性能的云服务&#xff0c;比格云从3月16日起&#xff0c;将上线“充值30天内&#xff…

数据结构 基础知识

一。逻辑结构: 是指数据对象中数据 素之间的相互关系。 其实这也是我 今后最需要关注的问题 逻辑结构分为以 四种1. 集合结构 2.线性结构 3.数形结构 4&#xff0c;图形结构 二。物理结构&#xff1a; 1&#xff0c;顺序存储结,2 2. 链式存储结构 一&#xff0c;时间复杂…

ruby 变量类中范围_Ruby中的类

ruby 变量类中范围Ruby类 (Ruby Classes) In the actual world, we have many objects which belong to the same category. For instance, I am working on my laptop and this laptop is one of those laptops which exist around the globe. So, this laptop is an object o…

以云计算的名义 驻云科技牵手阿里云

本文讲的是以云计算的名义 驻云科技牵手阿里云一次三个公司的牵手 可能会改变无数企业的命运 2017年4月17日&#xff0c;对于很多人来说可能只是个平常的工作日&#xff0c;但是对于国内无数的企业来说却可能是个会改变企业命运的日。驻云科技联合国内云服务提供商阿里云及国外…

浏览器端已支持 ES6 规范(包括 export import)

当然&#xff0c;是几个比较优秀的浏览器&#xff0c;既然是优秀的浏览器&#xff0c;大家肯定知道是那几款啦&#xff0c;我就不列举了&#xff0c;我用的是 chrome。 对 script 声明 type 为 module 后就可以享受 es6 规范所带来的模块快感了。 基础语法既然是全支持&#xf…

一文读懂深度学习框架下的目标检测(附数据集)

从简单的图像分类到3D位置估算&#xff0c;在机器视觉领域里从来都不乏有趣的问题。其中我们最感兴趣的问题之一就是目标检测。 如同其他的机器视觉问题一样&#xff0c;目标检测目前为止还没有公认最好的解决方法。在了解目标检测之前&#xff0c;让我们先快速地了解一下这个领…

设计一个应用程序,以在C#中的按钮单击事件上在MessageBox中显示TextBox中的文本...

Here, we took two controls on windows form that are TextBox and Button, named txtInput and btnShow respectively. We have to write C# code to display TextBox’s text in the MessageBox on Button Click. 在这里&#xff0c;我们在Windows窗体上使用了两个控件&…

Oracle优化器:星型转换(Star Query Transformation )

Oracle优化器&#xff1a;星型转换&#xff08;Star Query Transformation &#xff09;Star query是一个事实表&#xff08;fact table&#xff09;和一些维度表&#xff08;dimension&#xff09;的join。每个维度表都跟事实表通过主外键join&#xff0c;且每个维度表之间不j…

JavaScript | 声明数组并使用数组索引分配元素的代码

Declare an array, assign elements by indexes and print all elements in JavaScript. 声明一个数组&#xff0c;通过索引分配元素&#xff0c;并打印JavaScript中的所有元素。 Code: 码&#xff1a; <html><head><script>var fruits [];fruits[0]"…