Advertisement
NovaYoshi

block RAM?

Dec 20th, 2016
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. `timescale 1ns / 1ps
  2.  
  3. module blockram
  4.     (input clkA, // chipmunk clock
  5.      input clkB, // m2
  6.      input [7:0] dataInA,
  7.      output [7:0] dataOutA,
  8.      input [7:0] dataInB,
  9.      output [7:0] dataOutB,
  10.      input [11:0] addrBusA,
  11.      input [11:0] addrBusB,
  12.      input weMemA,
  13.      input weMemB,
  14.      input enableA,
  15.      input enableB);
  16.      
  17.     reg [7:0] dataBusOutputA;
  18.     reg [7:0] dataBusOutputB;
  19.    
  20.     wire enable1A = addrBusA[11:9] == 3'b000 && enableA;
  21.     wire enable1B = addrBusB[11:9] == 3'b000 && enableB;
  22.     wire enable2A = addrBusA[11:9] == 3'b001 && enableA;
  23.     wire enable2B = addrBusB[11:9] == 3'b001 && enableB;
  24.     wire enable3A = addrBusA[11:9] == 3'b010 && enableA;
  25.     wire enable3B = addrBusB[11:9] == 3'b010 && enableB;
  26.     wire enable4A = addrBusA[11:9] == 3'b011 && enableA;
  27.     wire enable4B = addrBusB[11:9] == 3'b011 && enableB;
  28.     wire enable5A = addrBusA[11:9] == 3'b100 && enableA;
  29.     wire enable5B = addrBusB[11:9] == 3'b100 && enableB;
  30.     wire enable6A = addrBusA[11:9] == 3'b101 && enableA;
  31.     wire enable6B = addrBusB[11:9] == 3'b101 && enableB;
  32.    
  33.     wire [7:0] out1A;
  34.     wire [7:0] out1B;
  35.     wire [7:0] out2A;
  36.     wire [7:0] out2B;
  37.     wire [7:0] out3A;
  38.     wire [7:0] out3B;
  39.     wire [7:0] out4A;
  40.     wire [7:0] out4B;
  41.     wire [7:0] out5A;
  42.     wire [7:0] out5B;
  43.     wire [7:0] out6A;
  44.     wire [7:0] out6B;
  45.    
  46.     RAMB4_S8_S8 ram1(.ADDRA(addrBusA[8:0]),
  47.                         .CLKA(clkA),
  48.                         .DIA(dataInA),
  49.                         .ENA(enable1A),
  50.                         .RSTA(),
  51.                         .WEA(weMemA),
  52.                         .DOA(out1A),
  53.                         .ADDRB(addrBusB[8:0]),
  54.                         .CLKB(clkB),
  55.                         .DIB(dataInB),
  56.                         .ENB(enable1B),
  57.                         .RSTB(),
  58.                         .WEB(weMemB),
  59.                         .DOB(out1B)
  60.                         );
  61.  
  62.     RAMB4_S8_S8 ram2(.ADDRA(addrBusA[8:0]),
  63.                         .CLKA(clkA),
  64.                         .DIA(dataInA),
  65.                         .ENA(enable2A),
  66.                         .RSTA(),
  67.                         .WEA(weMemA),
  68.                         .DOA(out2A),
  69.                         .ADDRB(addrBusB[8:0]),
  70.                         .CLKB(clkB),
  71.                         .DIB(dataInB),
  72.                         .ENB(enable2B),
  73.                         .RSTB(),
  74.                         .WEB(weMemB),
  75.                         .DOB(out2B)
  76.                         );
  77.     RAMB4_S8_S8 ram3(.ADDRA(addrBusA[8:0]),
  78.                         .CLKA(clkA),
  79.                         .DIA(dataInA),
  80.                         .ENA(enable3A),
  81.                         .RSTA(),
  82.                         .WEA(weMemA),
  83.                         .DOA(out3A),
  84.                         .ADDRB(addrBusB[8:0]),
  85.                         .CLKB(clkB),
  86.                         .DIB(dataInB),
  87.                         .ENB(enable3B),
  88.                         .RSTB(),
  89.                         .WEB(weMemB),
  90.                         .DOB(out3B)
  91.                         );
  92.     RAMB4_S8_S8 ram4(.ADDRA(addrBusA[8:0]),
  93.                         .CLKA(clkA),
  94.                         .DIA(dataInA),
  95.                         .ENA(enable4A),
  96.                         .RSTA(),
  97.                         .WEA(weMemA),
  98.                         .DOA(out4A),
  99.                         .ADDRB(addrBusB[8:0]),
  100.                         .CLKB(clkB),
  101.                         .DIB(dataInB),
  102.                         .ENB(enable4B),
  103.                         .RSTB(),
  104.                         .WEB(weMemB),
  105.                         .DOB(out4B)
  106.                         );
  107.     RAMB4_S8_S8 ram5(.ADDRA(addrBusA[8:0]),
  108.                         .CLKA(clkA),
  109.                         .DIA(dataInA),
  110.                         .ENA(enable5A),
  111.                         .RSTA(),
  112.                         .WEA(weMemA),
  113.                         .DOA(out5A),
  114.                         .ADDRB(addrBusB[8:0]),
  115.                         .CLKB(clkB),
  116.                         .DIB(dataInB),
  117.                         .ENB(enable5B),
  118.                         .RSTB(),
  119.                         .WEB(weMemB),
  120.                         .DOB(out5B)
  121.                         );
  122.     RAMB4_S8_S8 ram6(.ADDRA(addrBusA[8:0]),
  123.                         .CLKA(clkA),
  124.                         .DIA(dataInA),
  125.                         .ENA(enable6A),
  126.                         .RSTA(),
  127.                         .WEA(weMemA),
  128.                         .DOA(out6A),
  129.                         .ADDRB(addrBusB[8:0]),
  130.                         .CLKB(clkB),
  131.                         .DIB(dataInB),
  132.                         .ENB(enable6B),
  133.                         .RSTB(),
  134.                         .WEB(weMemB),
  135.                         .DOB(out6B)
  136.                         );
  137.  
  138.         always @* begin    
  139.             case (addrBusA[11:9])
  140.                 3'b000:
  141.                     dataBusOutputA = out1A;
  142.                 3'b001:
  143.                     dataBusOutputA = out2A;
  144.                 3'b010:
  145.                     dataBusOutputA = out3A;
  146.                 3'b011:
  147.                     dataBusOutputA = out4A;
  148.                 3'b100:
  149.                     dataBusOutputA = out5A;
  150.                 3'b101:
  151.                     dataBusOutputA = out6A;
  152.                 default:
  153.                     dataBusOutputA = 0;
  154.             endcase
  155.         end
  156.  
  157.         always @* begin    
  158.             case (addrBusB[11:9])
  159.                 3'b000:
  160.                     dataBusOutputB = out1B;
  161.                 3'b001:
  162.                     dataBusOutputB = out2B;
  163.                 3'b010:
  164.                     dataBusOutputB = out3B;
  165.                 3'b011:
  166.                     dataBusOutputB = out4B;
  167.                 3'b100:
  168.                     dataBusOutputB = out5B;
  169.                 3'b101:
  170.                     dataBusOutputB = out6B;
  171.                 default:
  172.                     dataBusOutputB = 0;
  173.             endcase
  174.         end
  175.        
  176.         assign dataOutA = dataBusOutputA;
  177.         assign dataOutB = dataBusOutputB;
  178.        
  179. endmodule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement