示例#1
0
def mkRAMDefinition(name,
                    datawidth=32,
                    addrwidth=10,
                    numports=2,
                    sync=True,
                    with_enable=False):
    m = Module(name)
    clk = m.Input('CLK')

    interfaces = []

    for i in range(numports):
        interface = RAMSlaveInterface(m,
                                      name + '_%d' % i,
                                      datawidth,
                                      addrwidth,
                                      with_enable=with_enable)
        if sync:
            interface.delay_addr = m.Reg(name + '_%d_daddr' % i, addrwidth)

        interfaces.append(interface)

    mem = m.Reg('mem', datawidth, length=2**addrwidth)

    for interface in interfaces:
        body = [
            vtypes.If(interface.wenable)(mem[interface.addr](interface.wdata))
        ]

        if sync:
            body.append(interface.delay_addr(interface.addr))

        if with_enable:
            body = vtypes.If(interface.enable)(*body)

        m.Always(vtypes.Posedge(clk))(body)

        if sync:
            m.Assign(interface.rdata(mem[interface.delay_addr]))
        else:
            m.Assign(interface.rdata(mem[interface.addr]))

    return m
示例#2
0
def mkRAMCore(name, datawidth=32, addrwidth=10, numports=2):
    m = Module(name)
    clk = m.Input('CLK')

    interfaces = []

    for i in range(numports):
        interface = RAMInterface(
            m, name + '_%d' % i, datawidth, addrwidth)
        interface.delay_addr = m.Reg(name + '_%d_daddr' % i, addrwidth)
        interfaces.append(interface)

    mem = m.Reg('mem', datawidth, length=2**addrwidth)

    for interface in interfaces:
        m.Always(vtypes.Posedge(clk))(
            vtypes.If(interface.wenable)(
                mem[interface.addr](interface.wdata)
            ),
            interface.delay_addr(interface.addr)
        )
        m.Assign(interface.rdata(mem[interface.delay_addr]))

    return m
示例#3
0
def mkRAMDefinition(name,
                    datawidth=32,
                    addrwidth=10,
                    numports=2,
                    initvals=None,
                    sync=True,
                    with_enable=False,
                    nocheck_initvals=False,
                    ram_style=None):
    m = Module(name)
    clk = m.Input('CLK')

    interfaces = []

    for i in range(numports):
        interface = RAMSlaveInterface(m,
                                      name + '_%d' % i,
                                      datawidth,
                                      addrwidth,
                                      with_enable=with_enable)
        if sync:
            interface.delay_addr = m.Reg(name + '_%d_daddr' % i, addrwidth)

        interfaces.append(interface)

    if ram_style is not None:
        m.EmbeddedCode(ram_style)

    mem = m.Reg('mem', datawidth, 2**addrwidth)

    if initvals is not None:
        if not isinstance(initvals, (tuple, list)):
            raise TypeError("initvals must be tuple or list, not '%s" %
                            str(type(initvals)))

        base = 16

        if not nocheck_initvals:
            new_initvals = []
            for initval in initvals:
                if isinstance(initval, int):
                    new_initvals.append(vtypes.Int(initval, datawidth,
                                                   base=16))
                elif isinstance(initval, vtypes.Int) and isinstance(
                        initval.value, int):
                    v = copy.deepcopy(initval)
                    v.width = datawidth
                    v.base = base
                    new_initvals.append(v)
                elif isinstance(initval, vtypes.Int) and isinstance(
                        initval.value, str):
                    v = copy.deepcopy(initval)
                    v.width = datawidth
                    if v.base != 2 and v.base != 16:
                        raise ValueError('base must be 2 or 16')
                    base = v.base
                    new_initvals.append(v)
                else:
                    raise TypeError("values of initvals must be int, not '%s" %
                                    str(type(initval)))

            initvals = new_initvals

        if 2**addrwidth > len(initvals):
            initvals.extend([
                vtypes.Int(0, datawidth, base=base)
                for _ in range(2**addrwidth - len(initvals))
            ])

        m.Initial(*[mem[i](initval) for i, initval in enumerate(initvals)])

    for interface in interfaces:
        body = [
            vtypes.If(interface.wenable)(mem[interface.addr](interface.wdata))
        ]

        if sync:
            body.append(interface.delay_addr(interface.addr))

        if with_enable:
            body = vtypes.If(interface.enable)(*body)

        m.Always(vtypes.Posedge(clk))(body)

        if sync:
            m.Assign(interface.rdata(mem[interface.delay_addr]))
        else:
            m.Assign(interface.rdata(mem[interface.addr]))

    return m
示例#4
0
文件: fsm.py 项目: yinxx/veriloggen
            ports[s.name] = out_d

        state_names = [self.state.name]
        state_names.extend([s.name for s in self.delayed_state.values()])

        for src in srcs:
            if isinstance(src, (vtypes.Parameter, vtypes.Localparam)):
                continue

            if src.name in state_names:
                continue

            if src.name in list(self.delayed_cond.keys()):
                rep_width = (src_rename_visitor.visit(src.width)
                             if src.width is not None else None)
                v = m.Reg(src.name, rep_width, initval=0)
                src_rename_dict[src.name] = v
                continue

            arg_name = 'i_%s' % src.name

            if src.length is not None:
                width = src.bit_length()
                length = src.length
                pack_width = vtypes.Mul(width, length)
                out_line = self.m.TmpWire(pack_width, prefix='_%s' % self.name)
                i = self.m.TmpGenvar(prefix='i')
                v = out_line[i * width:(i + 1) * width]
                g = self.m.GenerateFor(i(0), i < length, i(i + 1))
                p = g.Assign(v(src[i]))