zoukankan      html  css  js  c++  java
  • PCI Express(六)

    原文地址: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 = 1'b0;
    
    // then we create a state machine that triggers when we get a PCI Express memory read or write
    reg RXstate;
    reg [63:0] 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)
        1'b0: if(~trn_rsrc_rdy_n && ~trn_rsof_n && trn_rd[61:56]==6'b0_00000 && trn_rd[41:32]==10'h001)
        begin 
            RXstate <= 1'b1;
            RXrd <= trn_rd;
        end
        // then the second state waits for the end of the transaction
        1'b1: if(~trn_rsrc_rdy_n) RXstate <= 1'b0;
    endcase

    Now we are ready to update the LEDs.

    wire [31:0] RXaddr = trn_rd[63:32];   // memory address (read or write) (valid during the second state of the state machine)
    wire [31:0] RXdata = trn_rd[31:0];   // memory data (for a write) (valid during the second state of the state machine)
    
    wire RXrdwr = RXrd[62];  // 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 [1:0] LEDs;
    always @(posedge clk) if(RXwrite) LEDs <= RXdata[1:0];

    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.

  • 相关阅读:
    使用CustomValidate自定义验证控件
    C#中金额的大小写转换
    Andriod出错之Unable to build: the file dx.jar was not loaded from the SDK folder!
    VC 编写的打字练习
    机房工作笔记Ping只有单向通
    web服务协同学习笔记(1)
    Dll 学习3 将MDI子窗口封装在DLL中
    机房工作学习文件共享
    Andriod出错之Failed to find an AVD compatible with target 'Android 2.2'
    Andriod出错之wrapper was not properly loaded first
  • 原文地址:https://www.cnblogs.com/christsong/p/5721660.html
Copyright © 2011-2022 走看看