Merge pull request #129 from antmicro/8-16-bit-init

phy/model: add support for 8/16-bit wide SDR memory init
This commit is contained in:
enjoy-digital 2020-02-04 11:29:28 +01:00 committed by GitHub
commit 4a3ad56146
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 2 deletions

View File

@ -17,6 +17,8 @@ from litedram.phy.dfi import *
from functools import reduce from functools import reduce
from operator import or_ from operator import or_
import struct
# Bank Model --------------------------------------------------------------------------------------- # Bank Model ---------------------------------------------------------------------------------------
class BankModel(Module): class BankModel(Module):
@ -136,6 +138,17 @@ class SDRAMPHYModel(Module):
strs = ''.join('{:08x}'.format(x) for x in reversed(ints)) strs = ''.join('{:08x}'.format(x) for x in reversed(ints))
new_init[i//model_data_ratio] = int(strs, 16) new_init[i//model_data_ratio] = int(strs, 16)
init = new_init init = new_init
elif model_data_ratio == 0:
assert data_width_bytes in [1, 2]
model_data_ratio = 4 // data_width_bytes
struct_unpack_patterns = {1: "4B", 2: "2H"}
new_init = [0]*int(len(init)*model_data_ratio)
for i in range(len(init)):
new_init[model_data_ratio*i:model_data_ratio*(i+1)] = struct.unpack(
struct_unpack_patterns[data_width_bytes],
struct.pack("I", init[i])
)[0:model_data_ratio]
init = new_init
if address_mapping == "ROW_BANK_COL": if address_mapping == "ROW_BANK_COL":
for row in range(nrows): for row in range(nrows):
@ -199,8 +212,6 @@ class SDRAMPHYModel(Module):
bank_init = [[] for i in range(nbanks)] bank_init = [[] for i in range(nbanks)]
if init: if init:
# FIXME: Add support for 8/16-bit SDRAM
assert data_width >= 32
bank_init = self.__prepare_bank_init_data(init, nbanks, nrows, ncols, data_width, address_mapping) bank_init = self.__prepare_bank_init_data(init, nbanks, nrows, ncols, data_width, address_mapping)
# Banks ------------------------------------------------------------------------------------ # Banks ------------------------------------------------------------------------------------