.. _arch_model_timing_tutorial: Primitive Block Timing Modeling Tutorial ---------------------------------------- To accurately model an FPGA, the architect needs to specify the timing characteristics of the FPGA's primitives blocks. This involves two key steps: #. Specifying the logical timing characteristics of a primitive including: * whether primitive pins are sequential or combinational, and * what the timing dependencies are between the pins. #. Specifying the physical delay values These two steps separate the logical timing characteristics of a primitive, from the physically dependant delays. This enables a single logical netlist primitive type (e.g. Flip-Flop) to be mapped into different physical locations with different timing characteristics. The :ref:`FPGA architecture description ` describes the logical timing characteristics in the :ref:`models section `, while the physical timing information is specified on ``pb_types`` within :ref:`complex block `. The following sections illustrate some common block timing modeling approaches. Combinational block ~~~~~~~~~~~~~~~~~~~ A typical combinational block is a full adder, .. figure:: fa.* :width: 50% Full Adder where ``a``, ``b`` and ``cin`` are combinational inputs, and ``sum`` and ``cout`` are combinational outputs. We can model these timing dependencies on the model with the ``combinational_sink_ports``, which specifies the output ports which are dependant on an input port: .. code-block:: xml The physical timing delays are specified on any ``pb_type`` instances of the adder model. For example: .. code-block:: xml specifies that all the edges of 300ps delays, except to ``cin`` to ``cout`` edge which has a delay of 10ps. .. _dff_timing_modeling: Sequential block (no internal paths) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ A typical sequential block is a D-Flip-Flop (DFF). DFFs have no internal timing paths between their input and output ports. .. note:: If you are using BLIF's ``.latch`` directive to represent DFFs there is no need to explicitly provide a ```` definition, as it is supported by default. .. figure:: dff.* :width: 50% DFF Sequential model ports are specified by providing the ``clock=""`` attribute, where ```` is the name of the associated clock ports. The assoicated clock port must have ``is_clock="1"`` specified to indicate it is a clock. .. code-block:: xml The physical timing delays are specified on any ``pb_type`` instances of the model. In the example below the setup-time of the input is specified as 66ps, while the clock-to-q delay of the output is set to 124ps. .. code-block:: xml .. _mixed_sp_ram_timing_modeling: Mixed Sequential/Combinational Block ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ It is possible to define a block with some sequential ports and some combinational ports. In the example below, the ``single_port_ram_mixed`` has sequential input ports: ``we``, ``addr`` and ``data`` (which are controlled by ``clk``). .. figure:: mixed_sp_ram.* :width: 75% Mixed sequential/combinational single port ram However the output port (``out``) is a combinational output, connected internally to the ``we``, ``addr`` and ``data`` input registers. .. code-block:: xml In the ``pb_type`` we define the external setup time of the input registers (50ps) as we did for :ref:`dff_timing_modeling`. However, we also specify the following additional timing information: * The internal clock-to-q delay of the input registers (200ps) * The combinational delay from the input registers to the ``out`` port (800ps) .. code-block:: xml .. _seq_sp_ram_timing_modeling: Sequential block (with internal paths) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Some primitives represent more complex architecture primitives, which have timing paths contained completely within the block. The model below specifies a sequential single-port RAM. The ports ``we``, ``addr``, and ``data`` are sequential inputs, while the port ``out`` is a sequential output. ``clk`` is the common clock. .. figure:: seq_sp_ram.* :width: 75% Sequential single port ram .. code-block:: xml Similarly to :ref:`mixed_sp_ram_timing_modeling` the ``pb_type`` defines the input register timing: * external input register setup time (50ps) * internal input register clock-to-q time (200ps) Since the output port ``out`` is sequential we also define the: * internal *output* register setup time (60ps) * external *output* register clock-to-q time (300ps) The combinational delay between the input and output registers is set to 740ps. Note the internal path from the input to output registers can limit the maximum operating frequency. In this case the internal path delay is 1ns (200ps + 740ps + 60ps) limiting the maximum frequency to 1 GHz. .. code-block:: xml .. _seq_sp_ram_comb_inputs_timing_modeling: Sequential block (with internal paths and combinational input) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ A primitive may have a mix of sequential and combinational inputs. The model below specifies a mostly sequential single-port RAM. The ports ``addr``, and ``data`` are sequential inputs, while the port ``we`` is a combinational input. The port ``out`` is a sequential output. ``clk`` is the common clock. .. figure:: seq_comb_sp_ram.* :width: 75% Sequential single port ram with a combinational input .. code-block:: xml :emphasize-lines: 3 We use register delays similar to :ref:`seq_sp_ram_timing_modeling`. However we also specify the purely combinational delay between the combinational ``we`` input and sequential output ``out`` (800ps). Note that the setup time of the output register still effects the ``we`` to ``out`` path for an effective delay of 860ps. .. code-block:: xml :emphasize-lines: 17 .. _multiclock_dp_ram_timing_modeling: Multi-clock Sequential block (with internal paths) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ It is also possible for a sequential primitive to have multiple clocks. The following model represents a multi-clock simple dual-port sequential RAM with: * one write port (``addr1`` and ``data1``, ``we1``) controlled by ``clk1``, and * one read port (``addr2`` and ``data2``) controlled by ``clk2``. .. figure:: multiclock_dp_ram.* :width: 75% Multi-clock sequential simple dual port ram .. code-block:: xml On the ``pb_type`` the input and output register timing is defined similarly to :ref:`seq_sp_ram_timing_modeling`, except multiple clocks are used. .. code-block:: xml .. _clock_generator_timing_modeling: Clock Generators ~~~~~~~~~~~~~~~~ Some blocks (such as PLLs) generate clocks on-chip. To ensure that these generated clocks are identified as clocks, the associated model output port should be marked with ``is_clock="1"``. As an example consider the following simple PLL model: .. code-block:: xml The port named ``in_clock`` is specified as a clock sink, since it is an input port with ``is_clock="1"`` set. The port named ``out_clock`` is specified as a clock generator, since it is an *output* port with ``is_clock="1"`` set.