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 |
---|
27 | parameter addr_bits = 22; |
---|
28 | parameter addr_max = (1<<addr_bits)-1; |
---|
29 | parameter memfilename = "memory_hello.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 | //for(i=0; i<=1023; i=i+1) $display("mem_i = %x",mem[i]) ; |
---|
45 | end |
---|
46 | `endif |
---|
47 | |
---|
48 | assign flash_data = !flash_oen ? data :16'hzzzz; |
---|
49 | |
---|
50 | always @(posedge flash_clk) begin |
---|
51 | // Read cycle |
---|
52 | if (!flash_oen & flash_wen) |
---|
53 | begin |
---|
54 | //$display("INFO: flash: read from address %x data %x",flash_addr, mem[flash_addr]); |
---|
55 | data <= mem[flash_addr]; |
---|
56 | end |
---|
57 | else // Write cycle |
---|
58 | if (flash_oen & !flash_wen) |
---|
59 | $display("INFO: flash: write to address %x data %x (now disabled)",flash_addr,flash_data); |
---|
60 | //mem[flash_addr] <= flash_data; FIXME: errouneous spourious writes in flash |
---|
61 | end |
---|
62 | endmodule |
---|
63 | |
---|