|
3 | 3 |
|
4 | 4 | // Memory Interface Definitions |
5 | 5 | // |
6 | | -// This file defines abstract memory interface types that can be used |
7 | | -// for accessing frame buffer and palette data. The abstraction allows |
8 | | -// for future extension to support standard bus protocols like Wishbone |
9 | | -// or AXI without modifying the core rendering logic. |
10 | | -// |
11 | | -// Current implementation: Direct ROM access |
12 | | -// Future options: Wishbone, AXI-Lite, custom SRAM interface |
| 6 | +// Defines abstract memory interface macros for ROM access with 1-cycle latency. |
| 7 | +// Optimized for FPGA block RAM inference. |
13 | 8 |
|
14 | 9 | `ifndef MEMORY_IF_VH |
15 | 10 | `define MEMORY_IF_VH |
16 | 11 |
|
17 | | -// ============================================================================ |
18 | | -// Memory Interface Types |
19 | | -// ============================================================================ |
20 | | - |
21 | | -// Define memory interface type (can be extended in future) |
22 | | -// Currently only ROM is implemented, but architecture supports: |
23 | | -// - ROM: Direct embedded memory (current implementation) |
24 | | -// - WISHBONE: Wishbone Classic bus protocol |
25 | | -// - AXI: AXI4-Lite protocol |
26 | | -// - SRAM: External SRAM interface |
27 | | - |
28 | | -`ifndef MEM_IF_TYPE_WISHBONE |
29 | | -`ifndef MEM_IF_TYPE_AXI |
30 | | -`ifndef MEM_IF_TYPE_SRAM |
31 | | - `define MEM_IF_TYPE_ROM // Default to ROM |
32 | | -`endif |
33 | | -`endif |
34 | | -`endif |
35 | | - |
36 | | -// ============================================================================ |
37 | | -// ROM Interface (Current Implementation) |
38 | | -// ============================================================================ |
39 | | -// Direct synchronous read access with 1-cycle latency |
40 | | -// Optimized for FPGA block RAM inference |
41 | | - |
42 | | -`ifdef MEM_IF_TYPE_ROM |
43 | | - // No additional signals needed - uses reg arrays with synchronous read |
44 | | - // Read latency: 1 clock cycle |
45 | | - // Address width: Determined by memory size |
46 | | - // Data width: 4 bits for frame memory, 6 bits for palette |
47 | | -`endif |
48 | | - |
49 | | -// ============================================================================ |
50 | | -// Wishbone Interface (Future Extension) |
51 | | -// ============================================================================ |
52 | | -// Wishbone Classic single-cycle read protocol |
53 | | -// Reference: OpenCores Wishbone B4 specification |
54 | | - |
55 | | -`ifdef MEM_IF_TYPE_WISHBONE |
56 | | - // Master signals (from renderer to memory) |
57 | | - // wire wb_cyc; // Cycle active |
58 | | - // wire wb_stb; // Strobe (valid transaction) |
59 | | - // wire wb_we; // Write enable (0=read, 1=write) |
60 | | - // wire [ADDR_WIDTH-1:0] wb_adr; // Address |
61 | | - // wire [DATA_WIDTH-1:0] wb_dat_o; // Data output (write data) |
62 | | - |
63 | | - // Slave signals (from memory to renderer) |
64 | | - // wire wb_ack; // Acknowledge |
65 | | - // wire [DATA_WIDTH-1:0] wb_dat_i; // Data input (read data) |
66 | | - |
67 | | - // Read latency: 1 clock cycle (same as ROM) |
68 | | - // Supports pipelined access for higher throughput |
69 | | -`endif |
70 | | - |
71 | | -// ============================================================================ |
72 | | -// AXI4-Lite Interface (Future Extension) |
73 | | -// ============================================================================ |
74 | | -// AXI4-Lite read-only protocol for memory-mapped access |
75 | | -// Reference: ARM AMBA AXI4 specification |
76 | | - |
77 | | -`ifdef MEM_IF_TYPE_AXI |
78 | | - // Read address channel |
79 | | - // wire axi_arvalid; // Address valid |
80 | | - // wire [ADDR_WIDTH-1:0] axi_araddr; // Read address |
81 | | - // wire axi_arready; // Address ready (from slave) |
82 | | - |
83 | | - // Read data channel |
84 | | - // wire axi_rvalid; // Read data valid (from slave) |
85 | | - // wire [DATA_WIDTH-1:0] axi_rdata; // Read data |
86 | | - // wire [1:0] axi_rresp; // Response status |
87 | | - // wire axi_rready; // Read data ready |
88 | | - |
89 | | - // Read latency: 1-2 clock cycles |
90 | | - // More complex but industry-standard protocol |
91 | | -`endif |
92 | | - |
93 | | -// ============================================================================ |
94 | | -// Helper Macros for Memory Access |
95 | | -// ============================================================================ |
96 | | - |
97 | | -// Memory read operation (abstracts underlying protocol) |
| 12 | +// Memory read operation: synchronous read with 1-cycle latency |
98 | 13 | // Usage: `MEM_READ(data, memory, address) |
99 | | -`ifdef MEM_IF_TYPE_ROM |
100 | | - `define MEM_READ(data, memory, address) \ |
101 | | - data <= memory[address] |
102 | | -`elsif MEM_IF_TYPE_WISHBONE |
103 | | - // Future: Implement Wishbone read transaction |
104 | | - `define MEM_READ(data, memory, address) \ |
105 | | - /* TODO: Wishbone read transaction */ \ |
| 14 | +`define MEM_READ(data, memory, address) \ |
106 | 15 | data <= memory[address] |
107 | | -`elsif MEM_IF_TYPE_AXI |
108 | | - // Future: Implement AXI read transaction |
109 | | - `define MEM_READ(data, memory, address) \ |
110 | | - /* TODO: AXI read transaction */ \ |
111 | | - data <= memory[address] |
112 | | -`else |
113 | | - `define MEM_READ(data, memory, address) \ |
114 | | - data <= memory[address] |
115 | | -`endif |
116 | 16 |
|
117 | | -// Memory initialization (abstracts loading mechanism) |
| 17 | +// Memory initialization from hex file |
118 | 18 | // Usage: `MEM_INIT(memory, filename) |
119 | | -`ifdef MEM_IF_TYPE_ROM |
120 | | - `define MEM_INIT(memory, filename) \ |
| 19 | +`define MEM_INIT(memory, filename) \ |
121 | 20 | initial begin \ |
122 | 21 | $readmemh(filename, memory); \ |
123 | 22 | end |
124 | | -`elsif MEM_IF_TYPE_WISHBONE |
125 | | - // Future: External initialization through bus |
126 | | - `define MEM_INIT(memory, filename) \ |
127 | | - /* Initialized externally via Wishbone */ |
128 | | -`elsif MEM_IF_TYPE_AXI |
129 | | - // Future: External initialization through bus |
130 | | - `define MEM_INIT(memory, filename) \ |
131 | | - /* Initialized externally via AXI */ |
132 | | -`else |
133 | | - `define MEM_INIT(memory, filename) \ |
134 | | - initial begin \ |
135 | | - $readmemh(filename, memory); \ |
136 | | - end |
137 | | -`endif |
138 | | - |
139 | | -// ============================================================================ |
140 | | -// Memory Sizing Parameters |
141 | | -// ============================================================================ |
142 | | - |
143 | | -// These can be overridden for different memory configurations |
144 | | -`ifndef FRAME_MEM_ADDR_WIDTH |
145 | | - `define FRAME_MEM_ADDR_WIDTH 16 // 64K addresses (49,152 used) |
146 | | -`endif |
147 | 23 |
|
| 24 | +// Memory sizing parameters (can be overridden if needed) |
148 | 25 | `ifndef FRAME_MEM_DATA_WIDTH |
149 | 26 | `define FRAME_MEM_DATA_WIDTH 4 // 4-bit character indices |
150 | 27 | `endif |
151 | 28 |
|
152 | | -`ifndef PALETTE_MEM_ADDR_WIDTH |
153 | | - `define PALETTE_MEM_ADDR_WIDTH 4 // 16 palette entries |
154 | | -`endif |
155 | | - |
156 | 29 | `ifndef PALETTE_MEM_DATA_WIDTH |
157 | 30 | `define PALETTE_MEM_DATA_WIDTH 6 // 6-bit RGB (2R2G2B) |
158 | 31 | `endif |
|
0 commit comments