- Documentation
- Getting started
- Your first hardware design
Your first hardware design
This design toggles an LED about once a second from a 27 MHz clock.
Describe the hardware
Section titled “Describe the hardware”__fpga void blink(clock clk, bits<1>& led) { bits<25> divider = 0; bits<1> ledState = 1; __onRise(clk) { if (divider == 13500000) { divider = 0; ledState = ledState ^ 1; } else { divider = divider + 1; } } led = ledState;}clock clkis the clock domain.dividerandledStateare registers, because they are assigned inside__onRise. The initial values are their power-up values.bits<1>& ledis an output. Output ports are passed by reference.
Inspect it
Section titled “Inspect it”flux --emit=hardware blink.fluxmodule @blink [sequential] { clock %clk output %led : u1 state %divider : u25 [init=u25 0] state %ledState : u1 [init=u1 1] ...Print the look-up table mapping and its statistics:
flux --emit=lut --stats blink.fluxBind it to a board
Section titled “Bind it to a board”The host program calls the hardware function with board handles, then instantiates the result.
#include "blink.flux"#include "src/flux/boards.hpp"
int main() { flux::boards::TangNano20K board; auto clk = board.onBoardClock(); auto led = board.leds(0, 1);
auto design = blink(clk, led); board.instantiate(design); return 0;}Build an image
Section titled “Build an image”flux --emit=fs --board=tang-nano-20k --top=blink blink_board.flux --image-output=blink.fs --manifest-output=blink.jsonThe compiler reports the resources used and writes the configuration image with a manifest describing its pins. Loading it onto hardware is a separate, experimental step: see programming.