zoukankan      html  css  js  c++  java
  • RAM建模和初始化

    冯诺依曼提出的存储计算,计算存储,因此,几乎所有的CPU和ASIC都会使用存储器,它们的类型很多,包括异步RAM、同步RAM、ZBT RAM、DDR DRAM、ROM等。由于大部分的异步RAM和SRAM都是晶圆代工厂定制的,一次需要修改成适合于FPGA结构的Verilog等效模型。FPGA的综合工具会将这些模型推译出FPGA芯片特有的嵌入式RAM。RAM的特点是一拍写入,两拍读出。所有RAM的设计都是在速度和容量直接的折中。

    RAM的Verilog建模:

    方式1:

    //////////////////////////////////////////////////////////////////////
    ////  Generic Single-Port Synchronous RAM                         ////
    //////////////////////////////////////////////////////////////////////
    
    module or1200_spram_128x32(
        // Generic synchronous single-port RAM interface
        clk, rst, ce, we, oe, addr, di, doq
    );
    
    //
    // Default address and data buses width
    //
    parameter aw = 7;
    parameter dw = 32;
    
    //
    // Generic synchronous single-port RAM interface
    //
    input            clk;    // Clock
    input            rst;    // Reset
    input            ce;    // Chip enable input
    input            we;    // Write enable input
    input            oe;    // Output enable input
    input     [aw-1:0]    addr;    // address bus inputs
    input    [dw-1:0]    di;    // input data bus
    output    [dw-1:0]    doq;    // output data bus
    
    //
    // Generic single-port synchronous RAM model
    
    // Generic RAM's registers and wires
    //
    reg    [dw-1:0]    mem [(1<<aw)-1:0];    // RAM content
    reg    [aw-1:0]    addr_reg;        // RAM address register
    
    //
    // Data output drivers
    //
    assign doq = (oe) ? mem[addr_reg] : {dw{1'b0}};
    
    //
    // RAM address register
    //
    always @(posedge clk or posedge rst)
        if (rst == 1'b1)
            addr_reg <=  {aw{1'b0}};
        else if (ce)
            addr_reg <=  addr;
    //
    // RAM write
    //
    always @(posedge clk)
        if (ce && we)
            mem[addr] <=  di;
    
    endmodule

    方式2:

     1 module bram_inference(
     2       input clk,
     3       input [15:0] mem_din,
     4       input [9:0] mem_addr,
     5       input mem_we,
     6       output reg [15:0] mem_dout );
     7 
     8 reg [15:0] ram [0:1023];
     9 
    10 always (posedge clk)
    11 begin
    12       if(mem_we)
    13            ram[mem_addr] <= mem_din;
    14       mem_dout <= ram[mem_addr];
    15 end
    16 
    17 endmodule

    这两种方式建模的区别在于关键路径不同,方式1的关键路径在输入,方式2的关键路径在输出。

    RAM的初始化

    用Verilog建模的RAM可以采用$readmemh()和$readmemb()函数初始储存器。

    参考文献:

    [1]Evgeni Stavinov. 第53则 存储器的建模. FPGA 高手设计实战正经100则. 电子工业出版社. 2013, 10.

    [2] Single Port RAM Synchronous Read/Write .

    http://www.asic-world.com/examples/verilog/ram_sp_sr_sw.html. 2016,01,27.

    [3] Dual Port RAM Synchronous Read/Write.

    http://www.asic-world.com/examples/verilog/ram_dp_sr_sw.html . 2016,01,27.

    [4] ROM, EPROM, EEPROM.

    http://www.asic-world.com/examples/verilog/rom_eprom_eeprom.html

    [5] Memory Modeling. http://www.asic-world.com/verilog/memory_fsm1.html

    [6] $readmemb和$readmemh. http://lihaichuan.blog.51cto.com/498079/1198970

    [7] opencores.org/or1k/OR1K:Community_Portal.

  • 相关阅读:
    [uoj276][清华集训2016]汽水——分数规划+点分治
    [bzoj3143][Hnoi2013]游走——动态规划+高斯消元
    TypeScript笔记八
    TypeScript笔记七
    TypeScript笔记六
    TypeScript笔记五
    TypeScript笔记四
    TypeScript笔记三
    TypeScript笔记二
    TypeScript笔记一
  • 原文地址:https://www.cnblogs.com/dpc525/p/5164679.html
Copyright © 2011-2022 走看看