Ejemplo n.º 1
0
def generate_test(Circuit, func):
    #nfuncargs = check(circuit, func)
    sig = signature(func)
    nfuncargs = len(sig.parameters)
    assert nfuncargs + 1 < 8

    rom = testvectors(func)

    romb = ROMB(rom)
    counter = Counter(9)
    wire(1, romb.RE)
    wire(1, romb.RCLKE)
    wire(counter.O, romb.RADDR)

    circuit = Circuit(nfuncargs)

    circuit(*[romb.RDATA[i] for i in range(nfuncargs)])

    orr = Or(2)
    finished = DFF()
    f = finished(orr(counter.COUT, finished.O))

    xor = XOr(2)
    xor(circuit.O, romb.RDATA[nfuncargs])
    orr = Or(2)
    error = DFF()
    e = error(orr(xor.O, error.O))

    return f, e
Ejemplo n.º 2
0
def string_to_rom(string):
    ADDR_BITS = 9
    assert (len(string) <= (1 << ADDR_BITS))
    counter = Counter(ADDR_BITS)
    tab = [ord(string[i]) for i in range(len(string))]
    tab += [0 for _ in range((1 << ADDR_BITS) - len(string))]
    assert (len(tab) == 1 << ADDR_BITS)
    rom = Memory(height=(1 << ADDR_BITS), width=8, rom=tab, readonly=True)
    m.wire(1, rom.RE)
    return rom(counter.O)
Ejemplo n.º 3
0
import magma as m
from mantle import Counter
from loam.boards.icestick import IceStick

N = 8

icestick = IceStick()
icestick.Clock.on()
for i in range(N):
    icestick.J3[i].output().on()

main = icestick.main()

counter = Counter(32)
sawtooth = counter.O[8:16]

m.wire(sawtooth, main.J3)
Ejemplo n.º 4
0
import magma as m
from mantle import Counter
from loam.boards.tinyfpga import BX

N = 24

b = BX()
b.Clock.on() # 16Mhz default
b.LED.on()

main = b.DefineMain()
counter = Counter(N)
m.wire(counter.O[-1], main.LED)
m.EndCircuit()
Ejemplo n.º 5
0
import magma as m
from mantle import Counter, Memory
from loam.boards.icestick import IceStick


def sine(x):
    return np.sin(2 * math.pi * x)


x = np.linspace(0., 1., num=256, endpoint=False)
wavetable = 128 + 127 * sine(x)

icestick = IceStick()
icestick.Clock.on()
for i in range(8):
    icestick.J3[i].output().on()

main = icestick.main()

counter = Counter(16)
sawtooth = counter.O[8:16]

wavetable = wavetable.astype(int)
rom = Memory(height=256, width=16, rom=list(wavetable), readonly=True)

m.wire(rom(sawtooth)[0:8], main.J3)
m.wire(1, rom.RE)

m.EndCircuit()
Ejemplo n.º 6
0
from magma import wire, compile
from mantle import Counter
from loam.boards.goboard import GoBoard

board = GoBoard()
board.Clock.on()
board.D1.on()

main = board.main()

counter = Counter(22)
wire(counter.O[21], main.D1)

Ejemplo n.º 7
0
import magma as m
from mantle import Counter
from mantle.util.lhca import LHCA
from loam.boards.icestick import IceStick

icestick = IceStick()
icestick.Clock.on()
for i in range(8):
    icestick.J3[i].output().on()

main = icestick.main()

clock = Counter(22)

lhca = LHCA(8, has_ce=True)

m.wire(lhca(ce=clock.COUT), main.J3)

m.EndCircuit()
Ejemplo n.º 8
0
 def setup(self, main):
     setattr(main, self.name, Counter(self.n))
Ejemplo n.º 9
0
            states={'A', 'B', 'C', 'D'},
            initial='A',
            finals=set(),
            map={
                'A': {
                    '1': 'B'
                },
                'B': {
                    '2': 'C',
                    '3': 'D'
                },
                'C': {
                    '3': 'D',
                    '0': 'A'
                },
                'D': {
                    '0': 'A'
                },
            })

slow = Counter(16)
select = debounce(main.J1[4], slow.COUT)
pulse = falling(select)

FSM = DefineFSM('ABCD', myfsm)
f = FSM()

m.wire(main.J1[0:4], f.events)
m.wire(pulse, f.CE)
m.wire(f.states, main.J3)