瀏覽代碼

First commit. Makefile seemingly working.

Jonatan Gezelius 4 年之前
當前提交
a6f68da199
共有 4 個文件被更改,包括 113 次插入0 次删除
  1. 2 0
      .gitignore
  2. 40 0
      Makefile
  3. 18 0
      hdl_design/ha.vhd
  4. 53 0
      testbench/ha_tb.vhd

+ 2 - 0
.gitignore

@@ -0,0 +1,2 @@
+*~
+simulation/

+ 40 - 0
Makefile

@@ -0,0 +1,40 @@
+GHDL = ghdl
+
+VIEWER = gtkwave
+WAVEFILE = simulation/waves.vcd
+
+TOP_DESIGN = ha
+DESIGN_FILES_DIR = hdl_design
+DESIGN_FILES = ha.vhd
+DESIGN_FILES_FULL_PATH = $(addprefix $(DESIGN_FILES_DIR)/,$(DESIGN_FILES))
+
+WORK_DIR = simulation
+WORK_LIBRARY = work
+GHDL_OPTIONS = --work=$(WORK_LIBRARY) --workdir=$(WORK_DIR)
+
+TOP_TESTBENCH = ha_tb
+TEST_BENCHES_DIR = testbench
+TEST_BENCHES = ha_tb.vhd
+TEST_BENCHES_FULL_PATH = $(addprefix $(TEST_BENCHES_DIR)/,$(TEST_BENCHES))
+
+.PHONY: all clean analyze elaborate run view debug
+
+all: analyze elaborate run view
+
+analyze: $(DESIGN_FILES_FULL_PATH) $(TEST_BENCHES_FULL_PATH)
+	$(GHDL) -a $(GHDL_OPTIONS) $(DESIGN_FILES_FULL_PATH) $(TEST_BENCHES_FULL_PATH)
+
+elaborate: analyze
+	$(GHDL) -e $(GHDL_OPTIONS) $(TOP_TESTBENCH)
+
+run: elaborate
+	$(GHDL) -r $(GHDL_OPTIONS) $(TOP_TESTBENCH) --vcd=$(WAVEFILE)
+
+view: run
+	$(VIEWER) $(WAVEFILE)
+
+clean:
+	$(GHDL) --remove $(GHDL_OPTIONS)
+
+debug:
+	echo $(DESIGN_FILES_FULL_PATH)

+ 18 - 0
hdl_design/ha.vhd

@@ -0,0 +1,18 @@
+library ieee;
+use ieee.std_logic_1164.all;
+
+entity ha is
+  port
+    (
+      a : in std_logic;
+      b : in std_logic;
+      o : out std_logic;
+      c : out std_logic
+      );
+end entity;
+
+architecture beh of ha is
+begin
+  o <= a xor b;
+  c <= a and b;
+end architecture;

+ 53 - 0
testbench/ha_tb.vhd

@@ -0,0 +1,53 @@
+library ieee;
+use ieee.std_logic_1164.all;
+
+entity ha_tb is
+end entity;
+
+architecture beh of ha_tb is
+  component ha
+    port
+    (
+      a : in std_logic;
+      b : in std_logic;
+      o : out std_logic;
+      c : out std_logic
+      );
+  end component;
+
+  signal q, w, e, r : std_logic;
+begin
+
+  --ha_instance : ha port map (q => a, w => b, e => o, r => c);
+  ha_instance : ha port map (q, w, e, r);
+
+  process is
+  begin
+    
+    q <= 'X';
+    w <= 'X';
+    wait for 5 ns;
+
+    q <= '0';
+    w <= '0';
+    wait for 5 ns;
+
+    q <= '0';
+    w <= '1';
+    wait for 5 ns;
+
+    q <= '1';
+    w <= '0';
+    wait for 5 ns;
+
+    q <= '1';
+    w <= '1';
+    wait for 5 ns;
+
+    assert false report "end of simulation";
+    
+    wait;
+  end process;
+  
+  
+end architecture;