存在4种类型的sram(sram1,sram2,sram3,sram4),其中sram1和sram2属于SPSRAM类型,sram3和sram4属于DPSRAM类型,每种类型的sram对应3个mux值(4,8,16),每个mux值对应一个word_depth列表和一个io列表。使用python实现:建立一个类,类里面定义函数,当用户输入sram类型时,函数返回每个sram的每个mux对应word_depth_list最大值和io_list最大值。 示例: 当用户输入SPSRAM时,函数返回sram1和sram2中每个mux对应的word_depth_list最大值和io_list的最大值。
时间: 2023-04-02 18:01:18 浏览: 216
SRAM、DRAM、SDRAM 介绍
好的,我可以回答这个问题。以下是实现代码:
```python
class SRAM:
def __init__(self):
self.sram1 = {'mux4': {'word_depth_list': [1024, 2048, 4096], 'io_list': [8, 16, 32]},
'mux8': {'word_depth_list': [512, 1024, 2048], 'io_list': [16, 32, 64]},
'mux16': {'word_depth_list': [256, 512, 1024], 'io_list': [32, 64, 128]}}
self.sram2 = {'mux4': {'word_depth_list': [512, 1024, 2048], 'io_list': [8, 16, 32]},
'mux8': {'word_depth_list': [256, 512, 1024], 'io_list': [16, 32, 64]},
'mux16': {'word_depth_list': [128, 256, 512], 'io_list': [32, 64, 128]}}
self.sram3 = {'mux4': {'word_depth_list': [2048, 4096, 8192], 'io_list': [8, 16, 32]},
'mux8': {'word_depth_list': [1024, 2048, 4096], 'io_list': [16, 32, 64]},
'mux16': {'word_depth_list': [512, 1024, 2048], 'io_list': [32, 64, 128]}}
self.sram4 = {'mux4': {'word_depth_list': [1024, 2048, 4096], 'io_list': [8, 16, 32]},
'mux8': {'word_depth_list': [512, 1024, 2048], 'io_list': [16, 32, 64]},
'mux16': {'word_depth_list': [256, 512, 1024], 'io_list': [32, 64, 128]}}
def get_max_values(self, sram_type):
if sram_type == 'SPSRAM':
return {'sram1': {'mux4': {'word_depth_list': max(self.sram1['mux4']['word_depth_list']),
'io_list': max(self.sram1['mux4']['io_list'])},
'mux8': {'word_depth_list': max(self.sram1['mux8']['word_depth_list']),
'io_list': max(self.sram1['mux8']['io_list'])},
'mux16': {'word_depth_list': max(self.sram1['mux16']['word_depth_list']),
'io_list': max(self.sram1['mux16']['io_list'])}},
'sram2': {'mux4': {'word_depth_list': max(self.sram2['mux4']['word_depth_list']),
'io_list': max(self.sram2['mux4']['io_list'])},
'mux8': {'word_depth_list': max(self.sram2['mux8']['word_depth_list']),
'io_list': max(self.sram2['mux8']['io_list'])},
'mux16': {'word_depth_list': max(self.sram2['mux16']['word_depth_list']),
'io_list': max(self.sram2['mux16']['io_list'])}}}
elif sram_type == 'DPSRAM':
return {'sram3': {'mux4': {'word_depth_list': max(self.sram3['mux4']['word_depth_list']),
'io_list': max(self.sram3['mux4']['io_list'])},
'mux8': {'word_depth_list': max(self.sram3['mux8']['word_depth_list']),
'io_list': max(self.sram3['mux8']['io_list'])},
'mux16': {'word_depth_list': max(self.sram3['mux16']['word_depth_list']),
'io_list': max(self.sram3['mux16']['io_list'])}},
'sram4': {'mux4': {'word_depth_list': max(self.sram4['mux4']['word_depth_list']),
'io_list': max(self.sram4['mux4']['io_list'])},
'mux8': {'word_depth_list': max(self.sram4['mux8']['word_depth_list']),
'io_list': max(self.sram4['mux8']['io_list'])},
'mux16': {'word_depth_list': max(self.sram4['mux16']['word_depth_list']),
'io_list': max(self.sram4['mux16']['io_list'])}}}
else:
return None
```
你可以这样使用这个类:
```python
sram = SRAM()
print(sram.get_max_values('SPSRAM'))
# 输出:{'sram1': {'mux4': {'word_depth_list': 4096, 'io_list': 32}, 'mux8': {'word_depth_list': 2048, 'io_list': 64}, 'mux16': {'word_depth_list': 1024, 'io_list': 128}}, 'sram2': {'mux4': {'word_depth_list': 2048, 'io_list': 32}, 'mux8': {'word_depth_list': 1024, 'io_list': 64}, 'mux16': {'word_depth_list': 512, 'io_list': 128}}}
print(sram.get_max_values('DPSRAM'))
# 输出:{'sram3': {'mux4': {'word_depth_list': 8192, 'io_list': 32}, 'mux8': {'word_depth_list': 4096, 'io_list': 64}, 'mux16': {'word_depth_list': 2048, 'io_list': 128}}, 'sram4': {'mux4': {'word_depth_list': 4096, 'io_list': 32}, 'mux8': {'word_depth_list': 2048, 'io_list': 64}, 'mux16': {'word_depth_list': 1024, 'io_list': 128}}}
```
阅读全文