Ejemplo n.º 1
0
    class Counter(Circuit):
        name = name_
        io = IO(**dict(zip(args[::2], args[1::2])))

        add = DefineAdd(n, cin=cin, cout=cout)()
        mux = Mux(2, n)
        reg = Register(n, has_ce=has_ce, has_reset=has_reset)

        wire(reg.O, add.I0)
        wire(array(incr, n), add.I1)

        wire(add.O, mux.I0)
        wire(io.DATA, mux.I1)
        wire(io.LOAD, mux.S)

        reg(mux.O)

        next = False
        if next:
            wire(mux.O, io.O)
        else:
            wire(reg.O, io.O)

        if cin:
            wire(io.CIN, add.CIN)

        if cout:
            wire(add.COUT, io.COUT)  # this is fishy because of the LOAD
Ejemplo n.º 2
0
        def definition(Arb):
            ones = n * [1]
            y = DefineAdd(n)()(Arb.I, array(ones))  # y = x - 1

            def a(y):
                return LUT([0, 1, 0, 0])  # A0 & ~A1

            arb = join(col(a, n))
            arb(Arb.I, y)
            wire(arb.O, Arb.O)
Ejemplo n.º 3
0
def DefineCounterLoad(n,
                      cin=False,
                      cout=True,
                      incr=1,
                      next=False,
                      has_ce=False,
                      has_reset=False):

    name = _CounterName('CounterLoad', n, has_ce, has_reset)

    args = []
    args += ['DATA', In(UInt(n))]
    args += ['LOAD', In(Bit)]
    if cin:
        args += ['CIN', In(Bit)]

    args += ["O", Out(UInt(n))]
    if cout:
        args += ["COUT", Out(Bit)]

    args += ClockInterface(has_ce, has_reset)

    Counter = DefineCircuit(name, *args)

    add = DefineAdd(n, cin=cin, cout=cout)()
    mux = Mux(2, n)
    reg = Register(n, has_ce=has_ce, has_reset=has_reset)

    wire(reg.O, add.I0)
    wire(array(incr, n), add.I1)

    wire(add.O, mux.I0)
    wire(Counter.DATA, mux.I1)
    wire(Counter.LOAD, mux.S)

    reg(mux.O)

    if next:
        wire(mux.O, Counter.O)
    else:
        wire(reg.O, Counter.O)

    if cin:
        wire(Counter.CIN, add.CIN)

    if cout:
        wire(add.COUT, Counter.COUT)  # this is fishy because of the LOAD

    wireclock(Counter, reg)

    EndCircuit()

    return Counter
Ejemplo n.º 4
0
def DefineCounter(n,
                  cin=False,
                  cout=True,
                  incr=1,
                  next=False,
                  has_ce=False,
                  has_reset=False):

    name = _CounterName('Counter', n, has_ce, has_reset)

    args = []
    if cin:
        args += ['CIN', In(Bit)]

    args += ["O", Out(UInt(n))]
    if cout:
        args += ["COUT", Out(Bit)]

    args += ClockInterface(has_ce, has_reset)

    Counter = DefineCircuit(name, *args)

    add = DefineAdd(n, cin=cin, cout=cout)()
    reg = Register(n, has_ce=has_ce, has_reset=has_reset)

    wire(reg.O, add.I0)
    wire(array(incr, n), add.I1)

    reg(add.O)

    if next:
        wire(add.O, Counter.O)
    else:
        wire(reg.O, Counter.O)

    if cin:
        wire(Counter.CIN, add.CIN)

    if cout:
        wire(add.COUT, Counter.COUT)

    wireclock(Counter, reg)
    wiredefaultclock(Counter, reg)

    EndCircuit()

    return Counter
Ejemplo n.º 5
0
    class _Counter(m.Circuit):
        name = name_
        io = m.IO(**args)
        io += m.ClockIO(has_ce, has_reset)

        add = DefineAdd(n, cin=cin, cout=cout)()
        reg = Register(n, has_ce=has_ce, has_reset=has_reset)

        m.wire(reg.O, add.I0)
        m.wire(m.array(incr, n), add.I1)
        reg(add.O)

        next = False
        if next:
            m.wire(add.O, io.O)
        else:
            m.wire(reg.O, io.O)
        if cin:
            m.wire(io.CIN, add.CIN)
        if cout:
            m.wire(add.COUT, io.COUT)
Ejemplo n.º 6
0
def Add(n, cin=False, cout=False, **kwargs):
    return DefineAdd(n, cin=cin, cout=cout)(**kwargs)
Ejemplo n.º 7
0
def Add(n, cin=False, cout=False, T=m.Bits, **kwargs):
    return DefineAdd(n, cin=cin, cout=cout, T=T)(**kwargs)