Exemple #1
0
def main(n):
    import magma as m
    m.set_mantle_target('spartan3')
    from loam.boards.papilioone import PapilioOne
    from loam.shields.megawing import MegaWing
    from mantle import LUTN

    megawing = MegaWing(PapilioOne)
    megawing.Switch.on(n)
    megawing.LED.on(1)

    top = megawing.main()
    pown = 1 << n
    lut = LUTN(pown // 2 * [0, 1], pown)
    I = [top.SWITCH[i] for i in range(n)] if n != 1 else [top.SWITCH]
    m.wire(lut(*I), top.LED)
    m.EndCircuit()

    return top
Exemple #2
0
import magma as m
from magma.testing import check_files_equal

m.set_mantle_target('spartan3')


def compile_and_regress(name, vendor, main, *largs, **kwargs):
    build = 'build/' + name
    gold = 'gold/' + name
    m.compile(build, main(*largs, **kwargs), vendor=vendor)
    assert check_files_equal(__file__, build + '.v', gold + '.v')
    assert check_files_equal(__file__, build + '.pcf', gold + '.pcf')


def main(n):
    import magma as m
    m.set_mantle_target('spartan3')
    from loam.boards.papilioone import PapilioOne
    from loam.shields.megawing import MegaWing
    from mantle import LUTN

    megawing = MegaWing(PapilioOne)
    megawing.Switch.on(n)
    megawing.LED.on(1)

    top = megawing.main()
    pown = 1 << n
    lut = LUTN(pown // 2 * [0, 1], pown)
    I = [top.SWITCH[i] for i in range(n)] if n != 1 else [top.SWITCH]
    m.wire(lut(*I), top.LED)
    m.EndCircuit()
Exemple #3
0
    # they haven't already been defined. This allows implementations to
    # specialize a common module. For example, mantle40 defines a FullAdder, so
    # it will not use the generic FullAdder in common.
    module = importlib.import_module(f"mantle.{module}")
    if hasattr(module, "__all__"):
        names = module.__all__
    else:
        names = dir(module)
    for name in names:
        try:
            getattr(mantle, name)
        except AttributeError:
            scope.update({name: getattr(module, name)})

if m.mantle_target is None:
    m.set_mantle_target('coreir')

if m.mantle_target in ['coreir',
                       'ice40',
                       'spartan3',
                       'spartan6',
                       'kintex7',
                       'cyclone4',
    ]:

    #from mantle.primitives import *

    if m.mantle_target == 'coreir':
        from mantle.coreir import *
    elif m.mantle_target in ['ice40']:
        from mantle.lattice import *
Exemple #4
0
# coding: utf-8

# In[1]:

import magma as m

m.set_mantle_target("coreir")
import mantle


class FullAdder(m.Circuit):
    name = "FullAdderExample"  # Note: We use a unique name here
    # to avoid conflict with the Circuit
    # called FullAdder that is a part of
    # the mantle standard library
    IO = [
        "a",
        m.In(m.Bit), "b",
        m.In(m.Bit), "cin",
        m.In(m.Bit), "out",
        m.Out(m.Bit), "cout",
        m.Out(m.Bit)
    ]

    @classmethod
    def definition(io):
        # Generate the sum
        _sum = io.a ^ io.b ^ io.cin
        m.wire(_sum, io.out)
        # Generate the carry
        carry = (io.a & io.b) | (io.b & io.cin) | (io.a & io.cin)
Exemple #5
0
import magma
magma.set_mantle_target('spartan6')
from magma.bitutils import clog2
from bit1.asm import assemble, disassemble

N = 32
LOGN = clog2(N)

NI = 2
LOGNI = clog2(NI)

NO = 2
LOGNO = clog2(NO) + 1

def prog():
    from bit1.isa import set, clr
    from bit1.isa import mov, not_, and_, or_, xor
    from bit1.isa import nop, delay
    from bit1.isa import jump
    from bit1.isa import if0, if1, ifelse
    from bit1.isa import skip, skipif0, skipif1
    from bit1.isa import halt

    set( O0 )
    clr( O0 )
    mov(  I0, O0 )
    not_( I0, O0 )
    and_( I0, I1, O0 )
    or_( I0, I1, O0 )
    xor( I0, I1, O0 )
    delay(1)
Exemple #6
0
import math

import magma as m
m.set_mantle_target("ice40")

from mantle import Counter, Memory
from loam.boards.icestick import IceStick
from regex import *
from matcher import Matcher


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)


def to_fpga(rx):
    icestick = IceStick()
    icestick.Clock.on()
    icestick.D1.on()

    main = icestick.DefineMain()

    rom = string_to_rom('x' * 16)
Exemple #7
0
def pytest_configure(config):
    target = config.getoption('--target')
    magma.set_mantle_target(target)
Exemple #8
0
import magma as m
m.set_mantle_target("ice40")
import mantle as mantle

import lupa
from lupa import LuaRuntime
lua = LuaRuntime(unpack_returned_tuples=True)

lua.execute("package.path='./?.lua;/home/jhegarty/rigel/?.lua;/home/jhegarty/rigel/src/?.lua;/home/jhegarty/rigel/modules/?.lua;/home/jhegarty/rigel/misc/?.lua;/home/jhegarty/rigel/misc/compare/?.lua;/home/jhegarty/rigel/examples/?.lua'")

##############################################
# generate a rigel module like in regular lua...
R = lua.require("rigel")
G = lua.require("generators")
RM = lua.require("modules")
types = lua.require("types")
C = lua.require("examplescommon")

inp = R.input( types.uint(8) )
a = R.apply("a", C.plus100(types.uint(8)), inp)
b = R.apply("b", C.plus100(types.uint(8)), a)
p200 = RM["lambda"]( "p200", inp, b )

#######################################
def rigelTypeToMagmaType(ty):
    assert(types.isType(ty))
    if ty.isUint(ty):
        return m.UInt(ty.verilogBits(ty))
    else:
        assert(false)
    
Exemple #9
0
import magma
from magma.bitutils import seq2int
from magma.testing.coroutine import check, coroutine
from magma.simulator import PythonSimulator
from mantle import DefineJohnson

magma.set_mantle_target('ice40')


def johnson_counter(n):
    @coroutine
    def johnson_counter_():
        O = [False for _ in range(n)]
        yield
        while True:
            yield O
            O = [not O[-1]] + O[:-1]

    return johnson_counter_


def test_lfsr():
    n = 8
    Johnson8 = DefineJohnson(n=n)
    check(Johnson8, johnson_counter(n)(), 3 * n)