@@ -290,6 +290,105 @@ object UserDefined {
290290
291291:::
292292
293+ ## Layer-coloring
294+
295+ While layers are not allowed to influence the design or their parent layers, it
296+ is often useful and necessary to allow layer blocks to send information out of
297+ their containing modules to be read by layer blocks of the same layer or
298+ children layers. Hardware which has this optional property is said to be
299+ _ layer-colored_ . Both probes and wires can be layer-colored.
300+
301+ ### Layer-colored Probes and Wires
302+
303+ A layer-colored probe is a probe that exists if a user enables its corresponding
304+ layer during Verilog elaboration. Layer-colored probes are used to describe
305+ optional verification, debugging, or logging interfaces.
306+
307+ Layer-colored wires are used as temporary storage of defined probe values. They
308+ are used for communication between layer blocks of the same layer in the same
309+ module or as temporary storage when forwarding a probe to a port.
310+
311+ A layer-colored probe or wire may be the target of a ` define ` if the ` define ` is
312+ enabled when the color of the probe or wire is enabled. A layer-colored probe
313+ or wire may be ` read ` from if the color of the probe or wire is enabled when the
314+ ` read ` is enabled. Put differently, you may write to your layer or a child
315+ layer and you may read from your layer or a parent layer.
316+
317+ The example below shows two layer-colored probe ports and one layer-colored
318+ probe wire driven in legal ways:
319+
320+ ``` scala mdoc:reset
321+ import chisel3 ._
322+ import chisel3 .layer .{Layer , LayerConfig }
323+ import chisel3 .probe .{Probe , ProbeValue , define }
324+
325+ object A extends Layer (LayerConfig .Extract ())
326+ object B extends Layer (LayerConfig .Extract ())
327+
328+ class Foo extends RawModule {
329+ val a = IO (Output (Probe (Bool (), A )))
330+ val b = IO (Output (Probe (Bool (), B )))
331+
332+ layer.block(A ) {
333+ val a_wire = WireInit (false .B )
334+ define(a, ProbeValue (a_wire))
335+ }
336+
337+ val b_wire_probe = Wire (Probe (Bool (), B ))
338+ define(b, b_wire_probe)
339+
340+ layer.block(B ) {
341+ val b_wire = WireInit (false .B )
342+ define(b_wire_probe, ProbeValue (b_wire))
343+ }
344+
345+ }
346+ ```
347+
348+ ::: info
349+
350+ For more information, see the layer coloring section of the [ FIRRTL
351+ Specification] ( https://github.com/chipsalliance/firrtl-spec/releases/latest/download/spec.pdf ) .
352+
353+ :::
354+
355+ ### Enabling Layers
356+
357+ When working with layer-colored probes, it is often convenient to grant access
358+ to probes of one or more colors. E.g., testbenches often want to _ enable_ all
359+ layers in a design-under-test so that they gain access to layer-colored probe
360+ ports necessary for advanced design verification. Without an additional
361+ feature, this use case is poorly supported with just layer coloring. First, it
362+ is tedious to enclose all code inside a testbench in a layer block. Second, a
363+ testbench may need to read probes with colors that do not have a parent--child
364+ relationship. No layer block is capable of both legally reading from different
365+ probes and combining the results.
366+
367+ To support this use case, Chisel provides the ` layer.enable ` API. This API
368+ grants access to any layer-colored probes of instantiated modules for the
369+ enabled layer. The API may be used more than once to enable more than one
370+ layer.
371+
372+ The example below instantiates module ` Foo ` from the previous section. After
373+ enabling layers ` A ` and ` B ` , the module can read from probes with colors ` A ` and
374+ ` B ` and use their results in a single operation:
375+
376+ ``` scala mdoc:silent
377+ import chisel3 .layer .enable
378+ import chisel3 .probe .read
379+
380+ class Bar extends RawModule {
381+
382+ enable(A )
383+ enable(B )
384+
385+ val foo = Module (new Foo )
386+
387+ val c = read(foo.a) ^ read(foo.b)
388+
389+ }
390+ ```
391+
293392## Examples
294393
295394### Simple Extract Layer
0 commit comments