diff options
author | Patrick Lehmann <Patrick.Lehmann@plc2.de> | 2022-12-19 22:07:02 +0100 |
---|---|---|
committer | Patrick Lehmann <Patrick.Lehmann@plc2.de> | 2022-12-23 23:44:14 +0100 |
commit | 5853a37df7c9468a01d62f7b2eeee7d9773e72ca (patch) | |
tree | 8294b3c6850caa35070084c67d8c0d172981da85 /testsuite/pyunit/dom/examples | |
parent | 09b985a65469e28d46cf05a3d7e4957be84f69c7 (diff) | |
download | ghdl-5853a37df7c9468a01d62f7b2eeee7d9773e72ca.tar.gz ghdl-5853a37df7c9468a01d62f7b2eeee7d9773e72ca.tar.bz2 ghdl-5853a37df7c9468a01d62f7b2eeee7d9773e72ca.zip |
Restructured test example sourcefiles.
Diffstat (limited to 'testsuite/pyunit/dom/examples')
-rw-r--r-- | testsuite/pyunit/dom/examples/SimpleEntity.vhdl | 55 | ||||
-rw-r--r-- | testsuite/pyunit/dom/examples/SimplePackage.vhdl | 28 |
2 files changed, 83 insertions, 0 deletions
diff --git a/testsuite/pyunit/dom/examples/SimpleEntity.vhdl b/testsuite/pyunit/dom/examples/SimpleEntity.vhdl new file mode 100644 index 000000000..bdeae47e1 --- /dev/null +++ b/testsuite/pyunit/dom/examples/SimpleEntity.vhdl @@ -0,0 +1,55 @@ +-- Author: Patrick Lehmann +-- +-- A generic counter module used in the StopWatch example. +-- +library IEEE; +use IEEE.std_logic_1164.all; +use IEEE.numeric_std.all; + +use work.Utilities.all; + +-- Generic modulo N counter +-- +-- This component implements a generic modulo N counter with synchronous reset +-- and enable. It generates a wrap-around strobe signal when it roles from +-- MODULO-1 back to zero. +-- +-- .. hint:: +-- +-- A modulo N counter counts binary from zero to N-1. +-- +-- This component uses VHDL-2008 features like readback of ``out`` ports. +entity Counter is + generic ( + MODULO : positive; -- Modulo value. + BITS : natural := log2(MODULO) -- Number of expected output bits. + ); + port ( + Clock : in std_logic; -- Component clock + Reset : in std_logic; -- Component reset (synchronous) + Enable : in std_logic; -- Component enable (synchronous) + + Value : out unsigned(BITS - 1 downto 0); -- Current counter value + WrapAround : out std_logic -- Strobe output on change from MODULO-1 to zero + ); +end entity; + + +-- Synthesizable and simulatable variant of a generic counter. +architecture rtl of Counter is + signal CounterValue : unsigned(log2(MODULO) - 1 downto 0) := (others => '0'); +begin + process (Clock) + begin + if rising_edge(Clock) then + if ((Reset or WrapAround) = '1') then + CounterValue <= (others => '0'); + elsif (Enable = '1') then + CounterValue <= CounterValue + 1; + end if; + end if; + end process; + + Value <= resize(CounterValue, BITS); + WrapAround <= Enable when (CounterValue = MODULO - 1) else '0'; +end architecture; diff --git a/testsuite/pyunit/dom/examples/SimplePackage.vhdl b/testsuite/pyunit/dom/examples/SimplePackage.vhdl new file mode 100644 index 000000000..04df1c521 --- /dev/null +++ b/testsuite/pyunit/dom/examples/SimplePackage.vhdl @@ -0,0 +1,28 @@ +-- Author: Patrick Lehmann +-- +-- A collection of utility types and functions. +-- +library ieee; +use ieee.std_logic_1164.all; +use ieee.numeric_std.all; + +-- Utility package +package utilities is + -- Deferred constant to distinguish simulation from synthesis. + constant IS_SIMULATION : boolean; + +end package; + +package body utilities is + function simulation return boolean is + variable result : boolean := false; + begin + -- synthesis translate off + result := true; + -- synthesis translate on + return result; + end function; + + constant IS_SIMULATION : boolean := simulation; + +end package body; |