[12] | 1 | /* |
---|
| 2 | * * Memory Harness with Wishbone Slave interface |
---|
| 3 | * */ |
---|
| 4 | |
---|
| 5 | module flash ( |
---|
| 6 | flash_addr, flash_data, flash_oen, |
---|
| 7 | flash_wen, flash_cen, flash_clk, |
---|
| 8 | flash_adv, flash_rst |
---|
| 9 | ); |
---|
| 10 | |
---|
| 11 | // System inputs |
---|
| 12 | input flash_clk; // System Clock |
---|
| 13 | input flash_rst; // System Reset |
---|
| 14 | input flash_adv; // ??????????? |
---|
| 15 | |
---|
| 16 | // inputs |
---|
| 17 | |
---|
| 18 | input [21:0] flash_addr; |
---|
| 19 | input flash_oen; |
---|
| 20 | input flash_cen; |
---|
| 21 | input flash_wen; |
---|
| 22 | |
---|
| 23 | //dibir |
---|
| 24 | inout reg [15:0] flash_data; |
---|
| 25 | |
---|
| 26 | // Parameters |
---|
[17] | 27 | parameter addr_bits = 22; |
---|
[12] | 28 | parameter addr_max = (1<<addr_bits)-1; |
---|
| 29 | parameter memfilename = "memory.hex"; |
---|
| 30 | parameter memdefaultcontent = 16'h0000; |
---|
| 31 | |
---|
| 32 | // Wires |
---|
| 33 | reg[15:0] mem[addr_max:0]; // This is the memory! |
---|
| 34 | integer i; // Index |
---|
| 35 | reg[15:0] data; |
---|
| 36 | |
---|
| 37 | `ifdef DEBUG |
---|
| 38 | initial begin |
---|
| 39 | $display("INFO: MEMH %m: FLASH Memory Harness starting..."); |
---|
| 40 | $display("INFO: MEMH %m: %0d Address Bits / %0d Doublewords / %0d Bytes Total Memory", addr_bits, addr_max+1, (addr_max+1)*8); |
---|
| 41 | for(i=0; i<=addr_max; i=i+1) mem[i] = memdefaultcontent; |
---|
| 42 | $readmemh(memfilename, mem); |
---|
| 43 | $display("INFO: MEMH %m: Memory initialization completed"); |
---|
| 44 | end |
---|
| 45 | `endif |
---|
| 46 | |
---|
| 47 | assign flash_data = !flash_oen ? data :16'hzzzz; |
---|
| 48 | |
---|
| 49 | |
---|
| 50 | always @(posedge flash_clk) begin |
---|
| 51 | // Read cycle |
---|
| 52 | if (!flash_oen & flash_wen) |
---|
| 53 | data <= mem[flash_addr]; |
---|
| 54 | else // Write cycle |
---|
| 55 | if (flash_oen & !flash_wen) mem[flash_addr] <= flash_data; |
---|
| 56 | end |
---|
| 57 | endmodule |
---|
| 58 | |
---|