soc_bram.v 825 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. /*
  2. * soc_bram.v
  3. *
  4. * vim: ts=4 sw=4
  5. *
  6. * Copyright (C) 2020 Sylvain Munaut <tnt@246tNt.com>
  7. * SPDX-License-Identifier: CERN-OHL-P-2.0
  8. */
  9. `default_nettype none
  10. module soc_bram #(
  11. parameter integer AW = 8,
  12. parameter INIT_FILE = ""
  13. )(
  14. input wire [AW-1:0] addr,
  15. output reg [31:0] rdata,
  16. input wire [31:0] wdata,
  17. input wire [ 3:0] wmsk,
  18. input wire we,
  19. input wire clk
  20. );
  21. (* no_rw_check *)
  22. reg [31:0] mem [0:(1<<AW)-1];
  23. initial
  24. if (INIT_FILE != "")
  25. $readmemh(INIT_FILE, mem);
  26. always @(posedge clk) begin
  27. rdata <= mem[addr];
  28. if (we & ~wmsk[0]) mem[addr][ 7: 0] <= wdata[ 7: 0];
  29. if (we & ~wmsk[1]) mem[addr][15: 8] <= wdata[15: 8];
  30. if (we & ~wmsk[2]) mem[addr][23:16] <= wdata[23:16];
  31. if (we & ~wmsk[3]) mem[addr][31:24] <= wdata[31:24];
  32. end
  33. endmodule // soc_bram