Subversion Repositories ngs

Rev

Rev 61 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed | ?url?

  1. // part of NeoGS project (c) 2007-2008 NedoPC
  2. //
  3. // mem512b is 512 bytes synchronous memory, which maps directly to the EAB memory block of ACEX1K.
  4. // rdaddr is read address, dataout is the data read. Data is read with 1-clock latency, i.e. it
  5. //  appears after the positive clock edge, which locked rdaddr.
  6. // wraddr is write address, datain is data to be written. we enables write to memory: when it
  7. //  locks as being 1 at positive clock edge, data contained at datain is written to wraddr location.
  8. //
  9. // clk     __/``\__/``\__/``\__/``\__/``
  10. // rdaddr     |addr1|addr2|
  11. // dataout          |data1|data2|
  12. // wraddr           |addr3|addr4|
  13. // datain           |data3|data4|
  14. // we      _________/```````````\_______
  15. //
  16. // data1 is the data read from addr1, data2 is read from addr2
  17. // data3 is written to addr3, data4 is written to addr4
  18. //
  19. // simultaneous write and read to the same memory address lead to undefined read data.
  20.  
  21. module mem512b
  22. (
  23.         input  wire clk,
  24.  
  25.         input  wire re,
  26.         input  wire [8:0] rdaddr,
  27.         output reg  [7:0] dataout,
  28.  
  29.         input  wire we,
  30.         input  wire [8:0] wraddr,
  31.         input  wire [7:0] datain
  32. );
  33.  
  34.         reg [7:0] mem[0:511]; // memory block
  35.  
  36.  
  37.  
  38.         always @(posedge clk)
  39.         if( re )
  40.                 dataout <= mem[rdaddr];
  41.  
  42.         always @(posedge clk)
  43.         if( we )
  44.                 mem[wraddr] <= datain;
  45.  
  46. endmodule
  47.  
  48.