Files

128 lines
3.9 KiB
ReStructuredText
Raw Permalink Normal View History

2023-12-14 10:08:46 +13:00
Mapping to cell libraries
-------------------------
.. role:: yoscrypt(code)
:language: yoscrypt
While much of this documentation focuses on the use of Yosys with FPGAs, it is
also possible to map to cell libraries which can be used in designing ASICs.
This section will cover a brief `example project`_, available in the Yosys
2024-01-30 13:31:00 +13:00
source code under :file:`docs/source/code_examples/intro/`. The project
contains a simple ASIC synthesis script (:file:`counter.ys`), a digital design
written in Verilog (:file:`counter.v`), and a simple CMOS cell library
(:file:`mycells.lib`). Many of the early steps here are already covered in more
detail in the :doc:`/getting_started/example_synth` document.
2023-12-14 10:08:46 +13:00
.. note::
2024-01-30 13:31:00 +13:00
The :file:`counter.ys` script includes the commands used to generate the
images in this document. Code snippets in this document skip these commands;
2023-12-14 10:08:46 +13:00
including line numbers to allow the reader to follow along with the source.
To learn more about these commands, check out :ref:`interactive_show`.
2024-03-24 00:41:40 -04:00
.. _example project: https://github.com/YosysHQ/yosys/tree/main/docs/source/code_examples/intro
2023-12-14 10:08:46 +13:00
A simple counter
~~~~~~~~~~~~~~~~
First, let's quickly look at the design:
.. literalinclude:: /code_examples/intro/counter.v
:language: Verilog
:linenos:
:name: counter-v
2024-01-30 13:31:00 +13:00
:caption: :file:`counter.v`
2023-12-14 10:08:46 +13:00
This is a simple counter with reset and enable. If the reset signal, ``rst``,
is high then the counter will reset to 0. Otherwise, if the enable signal,
``en``, is high then the ``count`` register will increment by 1 each rising edge
of the clock, ``clk``.
Loading the design
~~~~~~~~~~~~~~~~~~
.. literalinclude:: /code_examples/intro/counter.ys
:language: yoscrypt
:lines: 1-3
:lineno-match:
2024-01-30 13:31:00 +13:00
:caption: :file:`counter.ys` - read design
2023-12-14 10:08:46 +13:00
Our circuit now looks like this:
.. figure:: /_images/code_examples/intro/counter_00.*
2024-05-11 10:40:54 +12:00
:class: width-helper invert-helper
2023-12-14 10:08:46 +13:00
:name: counter-hierarchy
2024-05-03 13:16:48 +12:00
``counter`` after `hierarchy`
2023-12-14 10:08:46 +13:00
Coarse-grain representation
~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. literalinclude:: /code_examples/intro/counter.ys
:language: yoscrypt
:lines: 7-10
:lineno-match:
2024-01-30 13:31:00 +13:00
:caption: :file:`counter.ys` - the high-level stuff
2023-12-14 10:08:46 +13:00
.. figure:: /_images/code_examples/intro/counter_01.*
2024-05-11 10:40:54 +12:00
:class: width-helper invert-helper
2023-12-14 10:08:46 +13:00
Coarse-grain representation of the ``counter`` module
Logic gate mapping
~~~~~~~~~~~~~~~~~~
.. literalinclude:: /code_examples/intro/counter.ys
:language: yoscrypt
:lines: 14-15
:lineno-match:
2024-01-30 13:31:00 +13:00
:caption: :file:`counter.ys` - mapping to internal cell library
2023-12-14 10:08:46 +13:00
.. figure:: /_images/code_examples/intro/counter_02.*
2024-05-11 10:40:54 +12:00
:class: width-helper invert-helper
2023-12-14 10:08:46 +13:00
2024-05-03 13:16:48 +12:00
``counter`` after `techmap`
2023-12-14 10:08:46 +13:00
Mapping to hardware
~~~~~~~~~~~~~~~~~~~
For this example, we are using a Liberty file to describe a cell library which
our internal cell library will be mapped to:
2024-09-03 10:20:24 +12:00
.. todo:: find a Liberty pygments style?
2023-12-14 10:08:46 +13:00
.. literalinclude:: /code_examples/intro/mycells.lib
2024-09-03 10:20:24 +12:00
:language: text
2023-12-14 10:08:46 +13:00
:linenos:
:name: mycells-lib
2024-01-30 13:31:00 +13:00
:caption: :file:`mycells.lib`
2023-12-14 10:08:46 +13:00
2024-05-03 13:38:01 +12:00
Recall that the Yosys built-in logic gate types are `$_NOT_`, `$_AND_`, `$_OR_`,
`$_XOR_`, and `$_MUX_` with an assortment of dff memory types.
2023-12-14 10:08:46 +13:00
:ref:`mycells-lib` defines our target cells as ``BUF``, ``NOT``, ``NAND``,
``NOR``, and ``DFF``. Mapping between these is performed with the commands
2024-05-03 13:16:48 +12:00
`dfflibmap` and `abc` as follows:
2023-12-14 10:08:46 +13:00
.. literalinclude:: /code_examples/intro/counter.ys
:language: yoscrypt
:lines: 20-27
:lineno-match:
2024-01-30 13:31:00 +13:00
:caption: :file:`counter.ys` - mapping to hardware
2023-12-14 10:08:46 +13:00
The final version of our ``counter`` module looks like this:
.. figure:: /_images/code_examples/intro/counter_03.*
2024-05-11 10:40:54 +12:00
:class: width-helper invert-helper
2023-12-14 10:08:46 +13:00
``counter`` after hardware cell mapping
2024-05-03 13:38:01 +12:00
Before finally being output as a verilog file with `write_verilog`, which can
then be loaded into another tool:
2023-12-14 10:08:46 +13:00
.. literalinclude:: /code_examples/intro/counter.ys
:language: yoscrypt
:lines: 30-31
:lineno-match:
2024-01-30 13:31:00 +13:00
:caption: :file:`counter.ys` - write synthesized design