macro_rules! clock { ($self: ident, $clock: ident, $($subs: ident), +) => { ... }; }
Expand description
The [clock!] macro is used to connect a set of devices to a common clock. The macro takes a variable number of arguments:
self- the struct containing the items to connect, normally justselfclock- the name of the field of the struct that holds the clock sourcesubs- the set of fields that should be clocked withclock. Note that the macro assumes that the sub-circuits being clocked all have clock inputs namedclock.
For example:
use rust_hdl_core::prelude::*;
#[derive(LogicBlock)]
pub struct SubWidget {
pub clock: Signal<In, Clock>,
}
#[derive(LogicBlock)]
pub struct Widget {
pub clock: Signal<In, Clock>,
pub dff_1: SubWidget,
pub dff_2: SubWidget,
}
impl Logic for Widget {
#[hdl_gen]
fn update(&mut self) {
// This is equivalent to:
// self.dff_1.clock.next = self.clock.val();
// self.dff_2.clock.next = self.clock.val();
clock!(self, clock, dff_1, dff_2);
}
}When you have many [DFF]s or several complex sub-circuits, the clock! macro can make it
easier to read the source code.