原文地址:http://www.fpga4fun.com/PCI-Express6.html

Let's try to control LEDs from the PCI Express bus.

Xilinx's "Endpoint Block Plus" core allows us to work at the transaction layer level, so it's just going to take us a few lines of code.
Instead of providing data on a 32-bit bus, "Endpoint Block Plus" uses a 64-bit bus (so we get twice as much data at each clock cycle). That's not a problem and a simple state-machine will handle simple memory reads & writes.

// we use signals from Xilinx's "Endpoint Block Plus"
// first we declare that we are always ready to get data
assign trn_rdst_rdy_n = 'b0; // then we create a state machine that triggers when we get a PCI Express memory read or write
reg RXstate;
reg [:] RXrd;
always @(posedge clk)
case(RXstate)
// we are going to handle simple memory reads & writes
// we know that with the "Endpoint Block Plus" core, such simple transactions always happens
// using two cycles so we just need a two-states state machine
// first, we wait for the beginning of a memory transaction with up to 32-bit data (i.e. with length=1)
'b0: if(~trn_rsrc_rdy_n && ~trn_rsof_n && trn_rd[61:56]==6'b0_00000 && trn_rd[:]=='h001)
begin
RXstate <= 'b1;
RXrd <= trn_rd;
end
// then the second state waits for the end of the transaction
'b1: if(~trn_rsrc_rdy_n) RXstate <= 1'b0;
endcase

Now we are ready to update the LEDs.

wire [:] RXaddr = trn_rd[:];   // memory address (read or write) (valid during the second state of the state machine)
wire [:] RXdata = trn_rd[:]; // memory data (for a write) (valid during the second state of the state machine) wire RXrdwr = RXrd[]; // 0 for a read, 1 for a write
wire RXRead = ~trn_rsrc_rdy_n & RXstate & ~RXrdwr; // true when a read is happening
wire RXwrite = ~trn_rsrc_rdy_n & RXstate & RXrdwr; // true when a write is happening // update two LEDs using the two LSBs from the data written
reg [:] LEDs;
always @(posedge clk) if(RXwrite) LEDs <= RXdata[:];

For a memory write, that's all there is to it. For a memory read, you need to create a response packet with the data to return. Generating an interrupt is also very easy - just assert a signal called "cfg_interrupt_n".

Want more? Check Dragon-E's startup-kit for a more complete example, and Xilinx's Endpoint Block Plus specification documentation for a description of all the signals.

PCI Express(六) - Simple transactions的更多相关文章

  1. PCI Express(四) - The transaction layer

    原文出处:http://www.fpga4fun.com/PCI-Express4.html 感觉没什么好翻译的,都比较简单,主要讲了TLP的帧结构 In the transaction layer, ...

  2. PCI Express(三) - A story of packets, stack and network

    原文出处:http://www.fpga4fun.com/PCI-Express3.html Packetized transactions PCI express is a serial bus. ...

  3. PCI Express(二) - Topology

    原文出处:http://www.fpga4fun.com/PCI-Express2.html Point-to-point architecture At 2.5Gbps, the PCI Expre ...

  4. PCI Express(一)- Connector

    在FPGA4FUN上看到一篇介绍PCI-E的帖子,简单易懂,适合入门,特地搬过来 原文地址:http://www.fpga4fun.com/PCI-Express.html 前言: As PCI Ex ...

  5. Down to the TLP: How PCI express devices talk (Part II)

    http://xillybus.com/tutorials/pci-express-tlp-pcie-primer-tutorial-guide-2 Data Link Layer Packets A ...

  6. Down to the TLP: How PCI express devices talk (Part I)

    http://xillybus.com/tutorials/pci-express-tlp-pcie-primer-tutorial-guide-1 Down to the TLP: How PCI ...

  7. [中英对照]How PCI Express Works | PCIe工作原理

    How PCI Express Works | PCIe工作原理 PCI Express is a high-speed serial connection that operates more li ...

  8. PCI Express(五) - Xilinx wizard

    原文地址:http://www.fpga4fun.com/PCI-Express5.html Xilinx makes using PCI express easy - they provide a ...

  9. Ubuntu 16.04 RTL8111/8168/8411 PCI Express Gigabit Ethernet Controller” 不能上网

    来源:http://forum.ubuntu.org.cn/viewtopic.php?f=116&t=463646 1.执行如下命令 uname -a sudo lspci -knn sud ...

随机推荐

  1. 获取贴图及IES文件

    最近看了一下以前写的关于收集贴图的函数...又完善了一下,老链接:http://www.cnblogs.com/3dxy/p/3988751.html fn saveusedmaps spath se ...

  2. hdu 1010 深搜+剪枝

    深度搜索 剪枝 还不是很理解 贴上众神代码 //http://blog.csdn.net/vsooda/article/details/7884772#include<iostream> ...

  3. 【总结】matlab求两个序列的相关性

    首先说说自相关和互相关的概念.  自相关 在统计学中的定义,自相关函数就是将一个有序的随机变量系列与其自身作比较.每个不存在相位差的系列,都与其都与其自身相似,即在此情况下,自相关函数值最大. 在信号 ...

  4. JavaScript数据类型之隐式类型转换

    JavaScript的数据类型分为七种,分别为null,undefined,boolean,string,number,object,symbol ( ECMAScript 2015新增).objec ...

  5. iscsi与multipath

    2016-10-01/21:07:24 http://www.cnblogs.com/wuchanming/p/4019660.htmlhttp://czmmiao.iteye.com/blog/20 ...

  6. ubuntu安装php5.3

    sudo -i wget http://in1.php.net/distributions/php-5.3.29.tar.bz2 .tar.bz2 cd php- apt-get install li ...

  7. oracle for循环查找结果

    -- Call the procedure begin ' ) loop dbms_output.put_line('v_rlt = '||v_rlt.ID||v_rlt.inspection_no) ...

  8. android模拟器停在Waiting for HOME解决方案

    直接打开Android SDK Manager然后再从Android SDK Manager里的tools打开Android AVD Manager,删除掉在Eclipse里创建的模拟器.并在新建一个 ...

  9. Redis的AOF是怎么实现的

    今天通过阅读AOF的实现代码,牵出了许多本来不是必须的话题,也都记下来先: Redis自己搞了一套事件循环机制: http://itindex.net/detail/26944-redis-%E4%B ...

  10. 编译Docker<v1.9.0>源码和初级安装

    本文主要介绍了如何在POWER CPU处理器上编译和安装Docker服务.很多时候,我们都需要自己编译Docker源码,有的时候是由于自己的处理器没有对应的安装包,有的时候是由于当前的新版本还有发布, ...