hub75_linebuffer.v 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. * hub75_linebuffer.v
  3. *
  4. * vim: ts=4 sw=4
  5. *
  6. * Copyright (C) 2019 Sylvain Munaut <tnt@246tNt.com>
  7. * All rights reserved.
  8. *
  9. * LGPL v3+, see LICENSE.lgpl3
  10. *
  11. * This program is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU Lesser General Public
  13. * License as published by the Free Software Foundation; either
  14. * version 3 of the License, or (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  19. * Lesser General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Lesser General Public License
  22. * along with this program; if not, write to the Free Software Foundation,
  23. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  24. */
  25. `default_nettype none
  26. module hub75_linebuffer #(
  27. parameter N_WORDS = 1,
  28. parameter WORD_WIDTH = 24,
  29. parameter ADDR_WIDTH = 6
  30. )(
  31. input wire [ADDR_WIDTH-1:0] wr_addr,
  32. input wire [(N_WORDS*WORD_WIDTH)-1:0] wr_data,
  33. input wire [N_WORDS-1:0] wr_mask,
  34. input wire wr_ena,
  35. input wire [ADDR_WIDTH-1:0] rd_addr,
  36. output reg [(N_WORDS*WORD_WIDTH)-1:0] rd_data,
  37. input wire rd_ena,
  38. input wire clk
  39. );
  40. integer i;
  41. reg [(N_WORDS*WORD_WIDTH)-1:0] ram [(1<<ADDR_WIDTH)-1:0];
  42. `ifdef SIM
  43. initial
  44. for (i=0; i<(1<<ADDR_WIDTH); i=i+1)
  45. ram[i] = 0;
  46. `endif
  47. always @(posedge clk)
  48. begin
  49. // Read
  50. if (rd_ena)
  51. rd_data <= ram[rd_addr];
  52. // Write
  53. if (wr_ena)
  54. for (i=0; i<N_WORDS; i=i+1)
  55. if (wr_mask[i])
  56. ram[wr_addr][((i+1)*WORD_WIDTH)-1 -: WORD_WIDTH] <= wr_data[((i+1)*WORD_WIDTH)-1 -: WORD_WIDTH];
  57. end
  58. endmodule // hub75_linebuffer