Coder Social home page Coder Social logo

loam's Introduction

Loam

Build Status

Loam is part of the Magma ecosystem of python programming tools for FPGAs.

Magma is a programming model for building hardware. The main abstraction in Magma is a Circuit. Circuits are created and then wired together. Magma circuits can be saved as structural verilog files.

Mantle is a library of useful circuits. Examples of mantle circuits are logic operators, arithmetic operators, comparison operators, multiplexers, decoders and encoders, flip-flops, registers, counters, shift regiseters and memory.

Loam extends Magma to model FPGAs, Peripherals, Parts and Boards. A part represents an IC and a board a PCB. Parts and boards are themselves circuits. Parts can be wired to other parts, and boards consist of a collection of parts and headers. Just like parts, boards can be wired together via their headers. Loam makes it easy to build applications on a variety of different FPGA demonstration boards.

FPGAs are a subclass of parts. Circuits can be created on an FPGAs using Magma. A special feature of loam are peripherals. Peripherals make it easy to instantiate hardware drivers on an FPGA for a part connected to the FPGA.

Loam implementations of boards are expected to implement drivers for all the parts on the board. For example, a Lattice Icestick board contains an Lattice ice40 FPGA, an FTDI USART, LEDS, and 3 headers. The IceStick board contains built-in drivers for the USART and LEDs. This makes it very easy to build an application running on a particular board.

For example, here is a complete application to blink an LED on the IceStick.

from magma import wire, EndDefine
from mantle import Counter
from loam.boards.icestick import IceStick

# Create an instance of an IceStick board
icestick = IceStick()

# Turn on the Clock peripheral
#  The clock is turned on because we are using a synchronous counter
icestick.Clock.on()

# Turn on the LED D5, also a peripheral
icestick.D5.on()

# Define a Magma Circuit on the FPGA on the IceStick
main = icestick.DefineMain()

# Create a 22-bit counter
N = 22
counter = Counter(N)

# Wire bit 21 of the counter to D5.
#  Since the clock frequency is 12Mhz,
#  bit 22 will toggle  approximately once per second
wire(counter.O[N-1], main.D5)

EndDefine()

This application is contained in the file blink.py. blink.py is compiled to verilog using magma.

$ magma -b icestick blink.py

The verilog (.v) and physical constraint files (.pcf) can then be compiled to a bitstream file using the open source yosys tool chain

$ cd build
$ make
yosys -q -p 'synth_ice40 -top main -blif blink.blif' blink.v
arachne-pnr -q -d 1k -o blink.txt -p blink.pcf blink.blif
icepack blink.txt blink.bin

Finally, we upload to the board using the open source icestorm tools.

$ make upload
iceprog blink.bin
...

It is that easy to make an LED blink using an FPGA!

Setup

$ git clone https://github.com/phanrahan/loam
$ cd loam

Install the Python dependencies. You can do this automatically using pip

$ pip install -r requirements.txt

Or manually

Install the pytest testing framework and the loam package, then run the test suite to check that everything is in order.

$ pip install pytest
$ pip install -e .
$ ./scripts/run_tests.sh

loam's People

Contributors

adamdai avatar leonardt avatar phanrahan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

loam's Issues

Setting individual pins in the same bank to different directionality doesn't work

Not sure if this is a bug or by design, but the following code doesn't work.

icestick = IceStick()
icestick.Clock.on()
for i in range(0, 4):
    icestick.J1[i].input().on()
for i in range(4, 8):
    icestick.J1[i].output().on()

In this case it sets all the pins on J1 to be inputs, rather than having half of them acting as outputs. If this is a requirement based on how the hardware actually works, we should raise an Error that let's the user know that this isn't allowed. Otherwise, we should make this work.

@phanrahan can you give me any insight into whether this is a bug or by design? I can take a stab at adding the error message or fixing the bug (so I can learn a little more about loam).

Make Loam Circuits Match Magma Circuits API

Currently, you can't get the string representation of some instances of loam boards. The magma repr function calls IO of the metaclass, and the loam board doesn't have an IO property.

>>> from loam.boards.icestick import IceStick
import lattice ice40
>>> icestick = IceStick()
>>> type(icestick)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/durst/dev/W17-8/magma/magma/circuit.py", line 108, in __repr__
    args = str(cls.IO)
AttributeError: type object 'IceStick' has no attribute 'IO'
>>>

Issue with bake tests on travis

6.27s$ ./bake
echo \$DYLD_LIBRARY_PATH
strace: test_ptrace_setoptions_followfork: PTRACE_TRACEME doesn't work: Operation not permitted
strace: test_ptrace_setoptions_followfork: unexpected exit status 1
fabricate: 'strace' exited with status 1
magma -b icestick lut4
strace: test_ptrace_setoptions_followfork: PTRACE_TRACEME doesn't work: Operation not permitted
strace: test_ptrace_setoptions_followfork: unexpected exit status 1
fabricate: 'strace' exited with status 1
magma -b icestick pll100
strace: test_ptrace_setoptions_followfork: PTRACE_TRACEME doesn't work: Operation not permitted
strace: test_ptrace_setoptions_followfork: unexpected exit status 1
fabricate: 'strace' exited with status 1
magma -b icestick ramb16
strace: test_ptrace_setoptions_followfork: PTRACE_TRACEME doesn't work: Operation not permitted
strace: test_ptrace_setoptions_followfork: unexpected exit status 1
fabricate: 'strace' exited with status 1
magma -b icestick adc1
strace: test_ptrace_setoptions_followfork: PTRACE_TRACEME doesn't work: Operation not permitted
strace: test_ptrace_setoptions_followfork: unexpected exit status 1
fabricate: 'strace' exited with status 1
magma -b icestick eq4
strace: test_ptrace_setoptions_followfork: PTRACE_TRACEME doesn't work: Operation not permitted
strace: test_ptrace_setoptions_followfork: unexpected exit status 1
fabricate: 'strace' exited with status 1
magma -b icestick counter4
strace: test_ptrace_setoptions_followfork: PTRACE_TRACEME doesn't work: Operation not permitted
strace: test_ptrace_setoptions_followfork: unexpected exit status 1
fabricate: 'strace' exited with status 1
magma -b icestick arbiter4
strace: test_ptrace_setoptions_followfork: PTRACE_TRACEME doesn't work: Operation not permitted
strace: test_ptrace_setoptions_followfork: unexpected exit status 1
fabricate: 'strace' exited with status 1
magma -b icestick dff
strace: test_ptrace_setoptions_followfork: PTRACE_TRACEME doesn't work: Operation not permitted
strace: test_ptrace_setoptions_followfork: unexpected exit status 1
fabricate: 'strace' exited with status 1
magma -b icestick lfsr8
strace: test_ptrace_setoptions_followfork: PTRACE_TRACEME doesn't work: Operation not permitted
strace: test_ptrace_setoptions_followfork: unexpected exit status 1
fabricate: 'strace' exited with status 1
magma -b icestick lhca8
strace: test_ptrace_setoptions_followfork: PTRACE_TRACEME doesn't work: Operation not permitted
strace: test_ptrace_setoptions_followfork: unexpected exit status 1
fabricate: 'strace' exited with status 1
magma -b icestick abuf
strace: test_ptrace_setoptions_followfork: PTRACE_TRACEME doesn't work: Operation not permitted
strace: test_ptrace_setoptions_followfork: unexpected exit status 1
fabricate: 'strace' exited with status 1
magma -b icestick lut1
strace: test_ptrace_setoptions_followfork: PTRACE_TRACEME doesn't work: Operation not permitted
strace: test_ptrace_setoptions_followfork: unexpected exit status 1
fabricate: 'strace' exited with status 1
magma -b icestick mux2
strace: test_ptrace_setoptions_followfork: PTRACE_TRACEME doesn't work: Operation not permitted
strace: test_ptrace_setoptions_followfork: unexpected exit status 1
fabricate: 'strace' exited with status 1
magma -b icestick gatedreg4
strace: test_ptrace_setoptions_followfork: PTRACE_TRACEME doesn't work: Operation not permitted
strace: test_ptrace_setoptions_followfork: unexpected exit status 1
fabricate: 'strace' exited with status 1
magma -b icestick rom1
strace: test_ptrace_setoptions_followfork: PTRACE_TRACEME doesn't work: Operation not permitted
strace: test_ptrace_setoptions_followfork: unexpected exit status 1
fabricate: 'strace' exited with status 1
magma -b icestick cascadedring
strace: test_ptrace_setoptions_followfork: PTRACE_TRACEME doesn't work: Operation not permitted
strace: test_ptrace_setoptions_followfork: unexpected exit status 1
fabricate: 'strace' exited with status 1
magma -b goboard blink
strace: test_ptrace_setoptions_followfork: PTRACE_TRACEME doesn't work: Operation not permitted
strace: test_ptrace_setoptions_followfork: unexpected exit status 1
fabricate: 'strace' exited with status 1
magma -b hx8kboard blink
strace: test_ptrace_setoptions_followfork: PTRACE_TRACEME doesn't work: Operation not permitted
strace: test_ptrace_setoptions_followfork: unexpected exit status 1
fabricate: 'strace' exited with status 1

LED numbering on HX8K board

On the physical Lattice ice40-HX8K board, the LEDs are numbered on the silkscreen D9 to D2 from left to right. In loam, these LEDs correspond to D1 thru D8. Not sure if we want to change around the numbering in loam to match the numbering the board.

loam package name in use on PYPI

The package name loam is currently in use on PYPI, so we won't be able to register the package https://pypi.org/project/loam/ for pip. We could explore a couple options here, such as appending a .py or distributing the package with magma/mantle (i.e. pip install magma installs mantle and loam). Or we look for an alternative name

Setup instructions are broken in README

There is no "requirements.txt" in the loam directory.
pytest tests also fails.

I notice that travis script is just calling './scripts/run_tests.sh'. What is the preferred testing mechanism for Loam?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.