Untitled

Pasted by Anonymous on Fri May 1 21:10:13 2020 UTC as Python
class DP16KD(Module):
	def __init__(self, width_a, width_b):
		addr_width_a = int(math.log2(18 * 1024 // width_a))
		addr_width_b = int(math.log2(18 * 1024 // width_b))

		self.ada = Signal(addr_width_a)
		self.dia = Signal(width_a)
		self.doa = Signal(width_a)
		self.csa = Signal(width_a // 8 or 1)
		self.wea = Signal()

		self.adb = Signal(addr_width_b)
		self.dib = Signal(width_b)
		self.dob = Signal(width_b)
		self.csb = Signal(width_b // 8 or 1)
		self.web = Signal()

		
		ram = Instance('DP16KD',
            p_DATA_WIDTH_A = width_a,
            p_DATA_WIDTH_B = width_b,
            p_WRITEMODE_A = 'READBEFOREWRITE',
            p_WRITEMODE_B = 'READBEFOREWRITE',

			**{'i_ADA%d' % i: self.ada[i] for i in range(addr_width_a)},
			**{'i_DIA%d' % i: self.dia[i] for i in range(width_a)},
			**{'o_DOA%d' % i: self.doa[i] for i in range(width_a)},
			**{'o_CSA%d' % i: self.csa[i] for i in range(width_a // 8 or 1)},
			i_WEA = self.wea,
			i_CLKA = ClockSignal('clka'),
			
			**{'i_ADB%d' % i: self.adb[i] for i in range(addr_width_b)},
			**{'i_DIB%d' % i: self.dib[i] for i in range(width_b)},
			**{'o_DOB%d' % i: self.dob[i] for i in range(width_b)},
			**{'o_CSB%d' % i: self.csb[i] for i in range(width_b // 8 or 1)},
			i_WEB = self.web,
			i_CLKB = ClockSignal('clkb'),
		)
		
		self.specials += ram