diff options
| author | mergify[bot] | 2022-04-12 00:09:55 +0000 |
|---|---|---|
| committer | GitHub | 2022-04-12 00:09:55 +0000 |
| commit | 898142ba05b04fb1602b249fd1ae81baa3f47f89 (patch) | |
| tree | 75304868c8e8a43abc79a5e125c51167fccce6b4 /docs | |
| parent | d766e8f7270579406d54abc9015d494cd199c6ce (diff) | |
Enhance views to [sometimes] support dynamic indexing and implement FlatIO (backport #2476) (#2479)
* Capture 1:1 mappings of Aggregates inside of views
This is implemented by including any corresponding Aggregates from the
DataView.mapping in the AggregateViewBinding.childMap (which is now of
type Map[Data, Data]).
This enables dynamically indexing Vecs that are themselves elements of
larger Aggregates in views when the corresponding element of the view is
a Vec of the same type. It also increases the number of cases where a
single Target can represent part of a view.
(cherry picked from commit 1f6b1ca14ccf86918065073c3f6f3626dd83a68e)
* Add FlatIO API for creating ports from Bundles without a prefix
(cherry picked from commit 772a3a1fe3b9372b7c2d7cd2d424b2adcd633cdb)
* [docs] Add FlatIO to the general cookbook
(cherry picked from commit b4159641350f238f0f899b69954142ce8ee11544)
Co-authored-by: Jack Koenig <koenig@sifive.com>
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/src/cookbooks/cookbook.md | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/docs/src/cookbooks/cookbook.md b/docs/src/cookbooks/cookbook.md index ae7c7bf6..b9e5db38 100644 --- a/docs/src/cookbooks/cookbook.md +++ b/docs/src/cookbooks/cookbook.md @@ -26,6 +26,7 @@ Please note that these examples make use of [Chisel's scala-style printing](../e * [How do I unpack a value ("reverse concatenation") like in Verilog?](#how-do-i-unpack-a-value-reverse-concatenation-like-in-verilog) * [How do I do subword assignment (assign to some bits in a UInt)?](#how-do-i-do-subword-assignment-assign-to-some-bits-in-a-uint) * [How do I create an optional I/O?](#how-do-i-create-an-optional-io) +* [How do I create I/O without a prefix?](#how-do-i-create-io-without-a-prefix) * [How do I minimize the number of bits used in an output vector](#how-do-i-minimize-the-number-of-bits-used-in-an-output-vector) * Predictable Naming * [How do I get Chisel to name signals properly in blocks like when/withClockAndReset?](#how-do-i-get-chisel-to-name-signals-properly-in-blocks-like-whenwithclockandreset) @@ -546,6 +547,50 @@ class ModuleWithOptionalIO(flag: Boolean) extends Module { } ``` +### How do I create I/O without a prefix? + +In most cases, you can simply call `IO` multiple times: + +```scala mdoc:silent:reset +import chisel3._ + +class MyModule extends Module { + val in = IO(Input(UInt(8.W))) + val out = IO(Output(UInt(8.W))) + + out := in +% 1.U +} +``` + +```scala mdoc:verilog +getVerilogString(new MyModule) +``` + +If you have a `Bundle` from which you would like to create ports without the +normal `val` prefix, you can use `FlatIO`: + +```scala mdoc:silent:reset +import chisel3._ +import chisel3.experimental.FlatIO + +class MyBundle extends Bundle { + val foo = Input(UInt(8.W)) + val bar = Output(UInt(8.W)) +} + +class MyModule extends Module { + val io = FlatIO(new MyBundle) + + io.bar := io.foo +% 1.U +} +``` + +Note that `io_` is nowhere to be seen! + +```scala mdoc:verilog +getVerilogString(new MyModule) +``` + ### How do I minimize the number of bits used in an output vector? Use inferred width and a `Seq` instead of a `Vec`: |
