aboutsummaryrefslogtreecommitdiffstats
path: root/examples/icezum
diff options
context:
space:
mode:
Diffstat (limited to 'examples/icezum')
-rw-r--r--examples/icezum/Makefile23
-rw-r--r--examples/icezum/blink.vhdl35
-rw-r--r--examples/icezum/counter.vhdl35
-rw-r--r--examples/icezum/icezum.pcf13
-rw-r--r--examples/icezum/led_on.vhdl15
-rw-r--r--examples/icezum/pushbutton.vhdl18
-rwxr-xr-xexamples/icezum/test.sh13
7 files changed, 152 insertions, 0 deletions
diff --git a/examples/icezum/Makefile b/examples/icezum/Makefile
new file mode 100644
index 0000000..ab6f5d7
--- /dev/null
+++ b/examples/icezum/Makefile
@@ -0,0 +1,23 @@
+PROJ ?= blink
+PIN_DEF = icezum.pcf
+DEVICE = hx1k
+
+all: report bin
+
+json: $(PROJ).vhdl
+ yosys -m ghdl -p 'ghdl $(PROJ).vhdl -e $(PROJ); synth_ice40 -json $@'
+
+asc: $(PIN_DEF) json
+ nextpnr-ice40 --$(DEVICE) --json json --pcf $(PIN_DEF) --asc $@
+
+bin: asc
+ icepack $< $@
+
+report: asc
+ icetime -d $(DEVICE) -mtr $@ $<
+
+clean:
+ rm -f json asc bin report work-obj93.cf
+
+.SECONDARY:
+.PHONY: all prog clean
diff --git a/examples/icezum/blink.vhdl b/examples/icezum/blink.vhdl
new file mode 100644
index 0000000..81c32ed
--- /dev/null
+++ b/examples/icezum/blink.vhdl
@@ -0,0 +1,35 @@
+library ieee;
+use ieee.std_logic_1164.all;
+use ieee.numeric_std.all;
+
+entity blink is
+ port (
+ clk : in std_logic;
+ led0, led1, led2, led3, led4, led5, led6, led7 : out std_logic
+ );
+end blink;
+
+architecture synth of blink is
+ signal blink: std_logic;
+begin
+ process (clk)
+ variable cnt : unsigned (23 downto 0); -- 3_000_000 requires 24 bits
+ begin
+ if rising_edge(clk) then
+ if cnt = 2_999_999 then
+ cnt := x"000000";
+ blink <= not blink;
+ else
+ cnt := cnt + 1;
+ end if;
+ end if;
+ end process;
+ led0 <= blink;
+ led1 <= blink;
+ led2 <= blink;
+ led3 <= blink;
+ led4 <= blink;
+ led5 <= blink;
+ led6 <= blink;
+ led7 <= blink;
+end synth;
diff --git a/examples/icezum/counter.vhdl b/examples/icezum/counter.vhdl
new file mode 100644
index 0000000..9cc4d7e
--- /dev/null
+++ b/examples/icezum/counter.vhdl
@@ -0,0 +1,35 @@
+library ieee;
+use ieee.std_logic_1164.all;
+use ieee.numeric_std.all;
+
+entity counter is
+ port (
+ clk : in std_logic;
+ led0, led1, led2, led3, led4, led5, led6, led7 : out std_logic
+ );
+end counter;
+
+architecture synth of counter is
+ signal clk_6hz : std_logic;
+begin
+ -- Presscaler
+ prescaler: process(clk)
+ variable timer : unsigned (20 downto 0) := (others=>'0');
+ begin
+ if rising_edge(clk) then
+ timer := timer + 1;
+ clk_6hz <= timer(20);
+ end if;
+ end process;
+
+ -- 8 bits counter
+ process (clk_6hz)
+ variable temp : unsigned (7 downto 0);
+ begin
+ if rising_edge(clk_6hz) then
+ temp:= temp + 1;
+ -- Show the counter on the icezum Alhambra leds
+ (led7, led6, led5, led4, led3, led2, led1, led0) <= temp;
+ end if;
+ end process;
+end synth;
diff --git a/examples/icezum/icezum.pcf b/examples/icezum/icezum.pcf
new file mode 100644
index 0000000..9ea27ad
--- /dev/null
+++ b/examples/icezum/icezum.pcf
@@ -0,0 +1,13 @@
+set_io sw1 10
+set_io sw2 11
+
+set_io clk 21
+
+set_io led0 95
+set_io led1 96
+set_io led2 97
+set_io led3 98
+set_io led4 99
+set_io led5 101
+set_io led6 102
+set_io led7 104
diff --git a/examples/icezum/led_on.vhdl b/examples/icezum/led_on.vhdl
new file mode 100644
index 0000000..a67ead4
--- /dev/null
+++ b/examples/icezum/led_on.vhdl
@@ -0,0 +1,15 @@
+library ieee;
+use ieee.std_logic_1164.all;
+use ieee.numeric_std.all;
+
+entity led_on is
+ port (led0, led1, led2, led3, led4, led5, led6, led7 : out std_logic);
+end led_on;
+
+architecture test of led_on is
+begin
+ -- Turn on the Led0
+ led0 <= '1';
+ -- Turn off the other leds
+ (led1, led2, led3, led4, led5, led6, led7) <= std_logic_vector'("0000000");
+end test;
diff --git a/examples/icezum/pushbutton.vhdl b/examples/icezum/pushbutton.vhdl
new file mode 100644
index 0000000..55ede2f
--- /dev/null
+++ b/examples/icezum/pushbutton.vhdl
@@ -0,0 +1,18 @@
+library ieee;
+use ieee.std_logic_1164.all;
+use ieee.numeric_std.all;
+
+entity pushbutton is
+ port (
+ sw1, sw2 : in std_logic;
+ led0, led7 : out std_logic
+ );
+end pushbutton;
+
+architecture synth of pushbutton is
+ signal a : std_logic;
+begin
+ a <= sw1 and sw2;
+ led0 <= a;
+ led7 <= not a;
+end synth;
diff --git a/examples/icezum/test.sh b/examples/icezum/test.sh
new file mode 100755
index 0000000..72da526
--- /dev/null
+++ b/examples/icezum/test.sh
@@ -0,0 +1,13 @@
+#!/usr/bin/env sh
+
+cd $(dirname $0)
+
+DOCKER_CMD="docker run --rm -v /$(pwd)://wrk -w //wrk"
+
+mkdir -p build
+
+for prj in blink counter led_on pushbutton; do
+ $DOCKER_CMD ghdl/synth:beta yosys -m ghdl -p "ghdl $prj.vhdl -e $prj; synth_ice40 -json build/json"
+ $DOCKER_CMD ghdl/synth:nextpnr nextpnr-ice40 --hx1k --json build/json --pcf icezum.pcf --asc build/asc
+ $DOCKER_CMD ghdl/synth:icestorm icepack build/asc build/$prj.bin
+done