Skip to content

Clocked logic

__onRise(clk) describes what happens on each rising edge of a clock. Values assigned there are held in registers.

All reads see the values from before the edge, and all assignments take effect together.

swap.flux
__fpga void swapRegisters(clock clk, bits<1> load, bits<8> inA, bits<8> inB,
bits<8>& a, bits<8>& b) {
__onRise(clk) {
if (load) {
a = inA;
b = inB;
} else {
a = b;
b = a;
}
}
}

When load is low, a and b exchange values on every edge. In software the two assignments would leave both equal.

A register that is not assigned on an edge keeps its value. Reset behavior is whatever logic you write:

counter.flux
__fpga void counter(clock clk, bits<1> reset, bits<32>& count) {
__onRise(clk) {
if (reset)
count = 0;
else
count = count + 1;
}
}

Designs with more than one clock need explicit synchronizers or FIFOs where signals cross between clock domains.