55# Copyright (c) 2021-2022 gatecat <[email protected] > 66# SPDX-License-Identifier: BSD-2-Clause
77
8- from amaranth import *
8+ from amaranth import Module , ClockSignal , ResetSignal , Signal , unsigned , ClockDomain
99from amaranth .lib import wiring
1010from amaranth .lib .wiring import In , Out , connect , flipped
1111from amaranth .utils import ceil_log2
1212
13- from amaranth .sim import Simulator
14-
1513from amaranth_soc import csr , wishbone
1614from amaranth_soc .memory import MemoryMap
1715
1816from chipflow_lib .platforms import BidirPinSignature , OutputPinSignature
1917
20- __all__ = ["HyperRAMPins" , " HyperRAM" ]
18+ __all__ = ["HyperRAM" ]
2119
2220
23- class HyperRAMPins (wiring .PureInterface ):
21+ class HyperRAM (wiring .Component ):
2422 class Signature (wiring .Signature ):
2523 def __init__ (self , * , cs_count = 1 ):
2624 super ().__init__ ({
@@ -31,15 +29,6 @@ def __init__(self, *, cs_count=1):
3129 "dq" : Out (BidirPinSignature (8 )),
3230 })
3331
34- def create (self , * , path = (), src_loc_at = 0 ):
35- return HyperRAMPins (cs_count = self .cs_count , src_loc_at = 1 + src_loc_at )
36-
37- def __init__ (self , * , cs_count = 1 , path = (), src_loc_at = 0 ):
38- super ().__init__ (self .Signature (cs_count = cs_count ), path = path , src_loc_at = 1 + src_loc_at )
39- self .cs_count = cs_count
40-
41-
42- class HyperRAM (wiring .Component ):
4332 class CtrlConfig (csr .Register , access = "rw" ):
4433 def __init__ (self , init_latency ):
4534 super ().__init__ ({
@@ -79,6 +68,7 @@ def __init__(self, mem_name=("mem",), *, pins, init_latency=7):
7968 "ctrl_bus" : In (csr .Signature (addr_width = regs .addr_width , data_width = regs .data_width )),
8069 "data_bus" : In (wishbone .Signature (addr_width = ceil_log2 (self .size >> 2 ), data_width = 32 ,
8170 granularity = 8 )),
71+ "pins" : Out (self .Signature ()),
8272 })
8373 self .ctrl_bus .memory_map = ctrl_memory_map
8474 self .data_bus .memory_map = data_memory_map
@@ -142,32 +132,32 @@ def elaborate(self, platform):
142132 self .pins .dq .oe .eq (1 ),
143133 counter .eq (6 ),
144134 # Assign CA
145- sr [47 ].eq (~ self .data_bus .we ), # R/W#
146- sr [46 ].eq (0 ), # memory space
147- sr [45 ].eq (1 ), # linear burst
148- sr [16 :45 ].eq (self .data_bus .adr [2 :21 ]), # upper address
149- sr [4 :16 ].eq (0 ), # RFU
150- sr [1 :3 ].eq (self .data_bus .adr [0 :2 ]), # lower address
151- sr [0 ].eq (0 ), # address LSB (0 for 32-bit xfers)
135+ sr [47 ].eq (~ self .data_bus .we ), # R/W#
136+ sr [46 ].eq (0 ), # memory space
137+ sr [45 ].eq (1 ), # linear burst
138+ sr [16 :45 ].eq (self .data_bus .adr [2 :21 ]), # upper address
139+ sr [4 :16 ].eq (0 ), # RFU
140+ sr [1 :3 ].eq (self .data_bus .adr [0 :2 ]), # lower address
141+ sr [0 ].eq (0 ), # address LSB (0 for 32-bit xfers)
152142 latched_adr .eq (self .data_bus .adr ),
153143 latched_we .eq (self .data_bus .we ),
154144 is_ctrl_write .eq (0 ),
155145 ]
156146 m .next = "WAIT_CA"
157- with m .If (self ._hram_cfg .f .val .w_stb ): # config register write
147+ with m .If (self ._hram_cfg .f .val .w_stb ): # config register write
158148 m .d .sync += [
159149 csn .eq (~ (1 << (self ._hram_cfg .f .val .w_data [16 :16 + ceil_log2 (self .cs_count )]))),
160150 self .pins .dq .oe .eq (1 ),
161151 counter .eq (6 ),
162152 # Assign CA
163- sr [47 ].eq (0 ), # R/W#
164- sr [46 ].eq (1 ), # memory space
165- sr [45 ].eq (1 ), # linear burst
166- sr [24 :45 ].eq (1 ), # upper address
167- sr [16 :24 ].eq (0 ), #
168- sr [4 :16 ].eq (0 ), # RFU
169- sr [1 :3 ].eq (0 ), # lower address
170- sr [0 ].eq (0 ), # address LSB (0 for 32-bit xfers)
153+ sr [47 ].eq (0 ), # R/W#
154+ sr [46 ].eq (1 ), # memory space
155+ sr [45 ].eq (1 ), # linear burst
156+ sr [24 :45 ].eq (1 ), # upper address
157+ sr [16 :24 ].eq (0 ), #
158+ sr [4 :16 ].eq (0 ), # RFU
159+ sr [1 :3 ].eq (0 ), # lower address
160+ sr [0 ].eq (0 ), # address LSB (0 for 32-bit xfers)
171161 latched_cfg .eq (self ._hram_cfg .f .val .w_data [0 :16 ]),
172162 is_ctrl_write .eq (1 ),
173163 ]
@@ -260,51 +250,3 @@ def elaborate(self, platform):
260250 ]
261251 m .next = "IDLE"
262252 return m
263-
264- def sim ():
265- pins = HyperRAMPins (cs_count = 1 )
266- m = Module ()
267- m .submodules .hram = hram = HyperRAM (pins = pins )
268- sim = Simulator (m )
269- sim .add_clock (1e-6 )
270- def process ():
271- yield hram .data_bus .adr .eq (0x5A5A5A )
272- yield hram .data_bus .dat_w .eq (0xF0F0F0F0 )
273- yield hram .data_bus .sel .eq (1 )
274- yield hram .data_bus .we .eq (1 )
275- yield hram .data_bus .stb .eq (1 )
276- yield hram .data_bus .cyc .eq (1 )
277- for i in range (100 ):
278- if (yield hram .data_bus .ack ):
279- yield hram .data_bus .stb .eq (0 )
280- yield hram .data_bus .cyc .eq (0 )
281- yield
282- yield hram .data_bus .adr .eq (0x5A5A5A )
283- yield hram .data_bus .sel .eq (1 )
284- yield hram .data_bus .we .eq (0 )
285- yield hram .data_bus .stb .eq (1 )
286- yield hram .data_bus .cyc .eq (1 )
287- yield pins .rwds .i .eq (1 )
288- yield pins .dq .i .eq (0xFF )
289- for i in range (100 ):
290- if (yield hram .data_bus .ack ):
291- yield hram .data_bus .stb .eq (0 )
292- yield hram .data_bus .cyc .eq (0 )
293- yield
294- yield hram .ctrl_bus .adr .eq (1 )
295- yield hram .ctrl_bus .dat_w .eq (0x55AA )
296- yield hram .ctrl_bus .sel .eq (0xF )
297- yield hram .ctrl_bus .we .eq (1 )
298- yield hram .ctrl_bus .stb .eq (1 )
299- yield hram .ctrl_bus .cyc .eq (1 )
300- for i in range (100 ):
301- if (yield hram .ctrl_bus .ack ):
302- yield hram .ctrl_bus .stb .eq (0 )
303- yield hram .ctrl_bus .cyc .eq (0 )
304- yield
305- sim .add_sync_process (process )
306- with sim .write_vcd ("hyperram.vcd" , "hyperram.gtkw" ):
307- sim .run ()
308-
309- if __name__ == '__main__' :
310- sim ()
0 commit comments