Hoodlum is a nice-looking hardware description language that compiles to Verilog. It wants to add stronger type guarantees and high-level concepts like enums (and structs/typedefs), but also make FPGA design easier and more fun to get involved with. To get started:
cargo install hoodlum
Add this to a file called blinky.hdl
:
```rust entity Main { in clk: bit, out LED1: bit, }
impl Main { def mut index: uint{..6000000}; on clk.posedge { if index == 6000000 - 1 { index <= 0; LED1 <= !LED1; } else { index <= index + 1; } } }
```
And run:
hoodlum blinky.hdl -o output.v
The tutorial and examples target the $20 iCEstick evaluation board and the IceStorm open source compiler toolchain. See "examples/blinky" for a simple blinking light.
NOTE: I'm learning Verilog and VHDL as I go along. Feel free to suggest ideas and best practices in the issues section!
sequence
generator.enc424j600
Ethernet PMOD board to send UDP packets. Requires an
enc424j600 PMOD board.Each example has a Makefile allowing you to run:
make && make flash
If you are getting errors on macOS about the device not being found, try running this first to unload the native FTDI driver:
sudo kextunload -b com.apple.driver.AppleUSBFTDI
You can highlight .hdl
scripts in Atom. Run the following to install the Atom Plugin:
cd language-hoodlum
apm link --local .
A Hoodlum script is composed of entity definitions in entity
blocks, and
logic definitions are in impl
blocks. The topmost entity is the Main
block.
entity Main {
in clk: bit,
out LED1: bit,
}
These top level entries reference pin definitions in your .pcf
file; see
"examples/blinky/icestick.pcf" for one for the iCEstick evaluation board.
Each of these entity members declares:
in
indicates a value will be read by the entity, and out
indicates a value will be written by the entity.impl
block.bit
wide, i.e. a logic value
of either 0
or 1
(or x
, in more complicated logic).Inside of a corresponding impl
block, we can reference these values:
``` impl Main { def mut toggle: bit;
def toggle_next: bit = !toggle;
on clk.negedge {
toggle <= toggle_next;
}
LED1 = toggle;
} ```
Let's break this down. First, we define a variable "toggle" which is one
bit wide. We declare this as def mut
, meaning the variable is mutable inside
of a on
block.
Next, we define a variable "toggle_next" which is not mutable. This means we have a stateless definition that requires no state (latches or flip-flops). We can declare its value inline with the definition or as a standalone declaration. Its value is always equal to the inverse of the "toggle" variable.
The on
block has a sensitivity to either the positive or negative falling edge
of a signal value. Inside of an on
block we can make assignments to mutable
variables using the nonblocking <=
or blocking :=
operators. Here, every
time we see a negative clock edge, we reset the "toggle" latch to be the value
of "toggle_next", i.e. the inverse of itself.
(Nonblocking definitions are deferred until the end of the on
block; this simplifies
stateful logic to all be set on the same clock impulse.)
Last, we declare a value for our output variable. LED1
is set to always be
equal to the value of the mutable "toggle" value.
At 12Mhz, you won't be able to see the LED toggling at this speed! See "examples/blinky/blinky.hdl" for how to use a counter to make it visible.
Each definition has a type, declared by the format def [mut] name: <type>
.
bit
declares a value that can hold 0
, 1
, or x
.bit[n]
declares a port that is n bits wide. You can reference individual
bits using a slice operator (e.g. myvariable[1]
) and set it at once with
a numeric literal (e.g. myvariable = 0b101101
, etc.)uint{..n}
and int{..n}
declares integers (unsigned and signed) whose max
value is n
(to the nearest power of two). This is shorthand for calculating
the maximum bit length for a given integer.Inside an entity, you can also define sub-entities:
``` entity Toggle { in value: bit, out opposite: bit, }
impl Toggle { ... }
entity Main { ... }
impl Main { def clkprime: bit; def toggle = Toggle { value: clk, opposite: clkprime, } } ```
Main declares a sub-entity Toggle with an input value given as "clk" and a output value as "clk_prime". Note that you have to declare output variables alongside the sub-entity to use them.
Open up any issues, discussion, ideas, or bugs in the issue tracker.
Goals:
Non-goals:
MIT or Apache-2.0.