block_ram_mod.v 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // vim: ts=4 sw=4 noexpandtab
  2. /*
  3. * Block RAM
  4. *
  5. * Copyright (c) 2019 Michael Buesch <m@bues.ch>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License along
  18. * with this program; if not, write to the Free Software Foundation, Inc.,
  19. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  20. */
  21. `ifndef BLOCK_RAM_MOD_V_
  22. `define BLOCK_RAM_MOD_V_
  23. module block_ram #(
  24. parameter ADDR_WIDTH = 16,
  25. parameter DATA_WIDTH = 8,
  26. parameter MEM_BYTES = 1024,
  27. ) (
  28. input clk,
  29. /* Port 0 */
  30. input [ADDR_WIDTH - 1 : 0] addr0,
  31. output reg [DATA_WIDTH - 1 : 0] rd_data0,
  32. input [DATA_WIDTH - 1 : 0] wr_data0,
  33. input wr0,
  34. /* Port 1 */
  35. input [ADDR_WIDTH - 1 : 0] addr1,
  36. output reg [DATA_WIDTH - 1 : 0] rd_data1,
  37. );
  38. reg [DATA_WIDTH - 1 : 0] mem [MEM_BYTES - 1 : 0];
  39. integer i;
  40. initial begin
  41. for (i = 0; i < MEM_BYTES; i++) begin
  42. mem[i] <= 0;
  43. end
  44. end
  45. always @(posedge clk) begin
  46. if (wr0) begin
  47. mem[addr0] <= wr_data0;
  48. end
  49. rd_data0 <= mem[addr0];
  50. rd_data1 <= mem[addr1];
  51. end
  52. endmodule
  53. `endif /* BLOCK_RAM_MOD_V_ */