aboutsummaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authoreine <6628437+eine@users.noreply.github.com>2020-01-19 03:25:43 +0000
committertgingold <tgingold@users.noreply.github.com>2020-01-19 04:25:43 +0100
commit910073d647e55d133494429d8c3a4bacffc32428 (patch)
tree6b1e616a1f670d44b03c1239ab5cba8aff15b909 /examples
parent175123cda990ee2b5cfac461bd8ec44956da302a (diff)
downloadghdl-yosys-plugin-910073d647e55d133494429d8c3a4bacffc32428.tar.gz
ghdl-yosys-plugin-910073d647e55d133494429d8c3a4bacffc32428.tar.bz2
ghdl-yosys-plugin-910073d647e55d133494429d8c3a4bacffc32428.zip
migrate from Travis to GHA and rework examples (#78)
* migrate from Travis to GHA * rework examples
Diffstat (limited to 'examples')
-rw-r--r--examples/ice40hx8k/leds.vhdl8
-rw-r--r--examples/ice40hx8k/pinmap.pcf13
-rw-r--r--examples/ice40hx8k/spin1.vhdl54
-rw-r--r--examples/ice40hx8k/spin2.vhdl29
-rw-r--r--examples/icestick/blink.vhdl23
-rw-r--r--examples/icestick/fixed1.vhdl4
-rw-r--r--examples/icestick/leds.pcf6
-rw-r--r--examples/icestick/leds.vhdl16
-rw-r--r--examples/icestick/multi1.vhdl83
-rw-r--r--examples/icestick/multi2.vhdl41
-rw-r--r--examples/icestick/rotate1.vhdl51
-rw-r--r--examples/icestick/rotate2.vhdl35
-rw-r--r--examples/icestick/rotate3.vhdl38
-rw-r--r--examples/icestick/rotate4.vhdl41
-rw-r--r--examples/icestick/spin1.vhdl51
-rw-r--r--examples/icestick/spin2.vhdl51
-rwxr-xr-xexamples/icestick/uart/README.md11
-rwxr-xr-xexamples/icestick/uart/hdl/uart_rx.vhd66
-rwxr-xr-xexamples/icestick/uart/hdl/uart_top.vhd49
-rwxr-xr-xexamples/icestick/uart/hdl/uart_tx.vhd62
-rwxr-xr-xexamples/icestick/uart/syn/constraints/uart.pcf6
-rwxr-xr-xexamples/icestick/uart/syn/synth.sh15
-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
29 files changed, 905 insertions, 0 deletions
diff --git a/examples/ice40hx8k/leds.vhdl b/examples/ice40hx8k/leds.vhdl
new file mode 100644
index 0000000..557585b
--- /dev/null
+++ b/examples/ice40hx8k/leds.vhdl
@@ -0,0 +1,8 @@
+library ieee;
+use ieee.std_logic_1164.all;
+use ieee.numeric_std.all;
+
+entity leds is
+ port (clk : in std_logic;
+ led1, led2, led3, led4, led5, led6, led7, led8 : out std_logic);
+end leds;
diff --git a/examples/ice40hx8k/pinmap.pcf b/examples/ice40hx8k/pinmap.pcf
new file mode 100644
index 0000000..6862c43
--- /dev/null
+++ b/examples/ice40hx8k/pinmap.pcf
@@ -0,0 +1,13 @@
+# example.pcf
+set_io --warn-no-port led1 B5
+set_io --warn-no-port led2 B4
+set_io --warn-no-port led3 A2
+set_io --warn-no-port led4 A1
+set_io --warn-no-port led5 C5
+set_io --warn-no-port led6 C4
+set_io --warn-no-port led7 B3
+set_io --warn-no-port led8 C3
+set_io --warn-no-port clk J3
+# FTDI
+set_io --warn-no-port ftdi_tx B12
+set_io --warn-no-port ftdi_rx B10
diff --git a/examples/ice40hx8k/spin1.vhdl b/examples/ice40hx8k/spin1.vhdl
new file mode 100644
index 0000000..7c50586
--- /dev/null
+++ b/examples/ice40hx8k/spin1.vhdl
@@ -0,0 +1,54 @@
+architecture spin1 of leds is
+ signal nrst : std_logic := '0';
+ signal clk_4hz: std_logic;
+ signal leds : std_ulogic_vector (1 to 5);
+begin
+ (led1, led2, led3, led4, led5) <= leds;
+ led6 <= '0';
+ led7 <= '0';
+ led8 <= '0';
+
+ process (clk)
+ variable cnt : unsigned (1 downto 0) := "00";
+ begin
+ if rising_edge (clk) then
+ if cnt = 3 then
+ nrst <= '1';
+ else
+ cnt := cnt + 1;
+ end if;
+ end if;
+ end process;
+
+ process (clk)
+ -- 3_000_000 is 0x2dc6c0
+ variable counter : unsigned (23 downto 0);
+ begin
+ if rising_edge(clk) then
+ if nrst = '0' then
+ counter := x"000000";
+ else
+ if counter = 2_999_999 then
+ counter := x"000000";
+ clk_4hz <= '1';
+ else
+ counter := counter + 1;
+ clk_4hz <= '0';
+ end if;
+ end if;
+ end if;
+ end process;
+
+ process (clk)
+ begin
+ if rising_edge(clk) then
+ if nrst = '0' then
+ -- Initialize
+ leds <= "11000";
+ elsif clk_4hz = '1' then
+ -- Rotate
+ leds <= (leds (4), leds (1), leds (2), leds (3), '0');
+ end if;
+ end if;
+ end process;
+end spin1;
diff --git a/examples/ice40hx8k/spin2.vhdl b/examples/ice40hx8k/spin2.vhdl
new file mode 100644
index 0000000..ccdab8b
--- /dev/null
+++ b/examples/ice40hx8k/spin2.vhdl
@@ -0,0 +1,29 @@
+architecture spin2 of leds is
+ signal clk_4hz: std_logic;
+ signal leds : std_ulogic_vector (1 to 8) := "11000000";
+begin
+ (led1, led2, led3, led4, led5, led6, led7, led8) <= leds;
+
+ process (clk)
+ -- 3_000_000 is 0x2dc6c0
+ variable counter : unsigned (23 downto 0);
+ begin
+ if rising_edge(clk) then
+ if counter = 2_999_999 then
+ counter := x"000000";
+ clk_4hz <= '1';
+ else
+ counter := counter + 1;
+ clk_4hz <= '0';
+ end if;
+ end if;
+ end process;
+
+ process (clk)
+ begin
+ if rising_edge(clk) and clk_4hz = '1' then
+ -- Rotate
+ leds <= (leds (8), leds (1), leds (2), leds (3), leds (4), leds (5), leds (6), leds (7));
+ end if;
+ end process;
+end spin2;
diff --git a/examples/icestick/blink.vhdl b/examples/icestick/blink.vhdl
new file mode 100644
index 0000000..d7e6dd4
--- /dev/null
+++ b/examples/icestick/blink.vhdl
@@ -0,0 +1,23 @@
+architecture blink of leds is
+ signal clk_4hz: std_logic;
+begin
+ process (clk)
+ -- 3_000_000 is 0x2dc6c0
+ variable counter : unsigned (23 downto 0);
+ begin
+ if rising_edge(clk) then
+ if counter = 2_999_999 then
+ counter := x"000000";
+ clk_4hz <= not clk_4hz;
+ else
+ counter := counter + 1;
+ end if;
+ end if;
+ end process;
+
+ led1 <= clk_4hz;
+ led2 <= clk_4hz;
+ led3 <= clk_4hz;
+ led4 <= clk_4hz;
+ led5 <= clk_4hz;
+end blink;
diff --git a/examples/icestick/fixed1.vhdl b/examples/icestick/fixed1.vhdl
new file mode 100644
index 0000000..b1bbf4b
--- /dev/null
+++ b/examples/icestick/fixed1.vhdl
@@ -0,0 +1,4 @@
+architecture fixed1 of leds is
+begin
+ (led1, led2, led3, led4, led5) <= std_logic_vector'("00101");
+end fixed1;
diff --git a/examples/icestick/leds.pcf b/examples/icestick/leds.pcf
new file mode 100644
index 0000000..397bdc4
--- /dev/null
+++ b/examples/icestick/leds.pcf
@@ -0,0 +1,6 @@
+set_io led1 99
+set_io led2 98
+set_io led3 97
+set_io led4 96
+set_io led5 95
+set_io clk 21
diff --git a/examples/icestick/leds.vhdl b/examples/icestick/leds.vhdl
new file mode 100644
index 0000000..95aa5cf
--- /dev/null
+++ b/examples/icestick/leds.vhdl
@@ -0,0 +1,16 @@
+library ieee;
+use ieee.std_logic_1164.all;
+use ieee.numeric_std.all;
+
+-- Led positions
+--
+-- I D3
+-- r
+-- D D2 D5 D4
+-- A
+-- D1
+--
+entity leds is
+ port (clk : in std_logic;
+ led1, led2, led3, led4, led5 : out std_logic);
+end leds;
diff --git a/examples/icestick/multi1.vhdl b/examples/icestick/multi1.vhdl
new file mode 100644
index 0000000..a304765
--- /dev/null
+++ b/examples/icestick/multi1.vhdl
@@ -0,0 +1,83 @@
+architecture multi1 of leds is
+ signal clk_4hz: std_logic;
+ signal clk_5sec : std_logic;
+ signal leds : std_ulogic_vector (1 to 5);
+begin
+ (led1, led2, led3, led4, led5) <= leds;
+
+ process (clk)
+ -- 3_000_000 is 0x2dc6c0
+ variable counter : unsigned (23 downto 0);
+ begin
+ if rising_edge(clk) then
+ if counter = 2_999_999 then
+ counter := x"000000";
+ clk_4hz <= '1';
+ else
+ counter := counter + 1;
+ clk_4hz <= '0';
+ end if;
+ end if;
+ end process;
+
+ process (clk)
+ variable counter5 : unsigned (4 downto 0);
+ begin
+ if rising_edge (clk) then
+ clk_5sec <= '0';
+ if clk_4hz = '1' then
+ if counter5 = 19 then
+ clk_5sec <= '1';
+ counter5 := "00000";
+ else
+ counter5 := counter5 + 1;
+ end if;
+ end if;
+ end if;
+ end process;
+
+ process (clk)
+ variable count : unsigned (1 downto 0);
+ variable pat_count : unsigned (0 downto 0);
+ begin
+ if rising_edge(clk) then
+ if clk_4hz = '1' then
+ case pat_count is
+ when "0" =>
+ case count is
+ when "00" =>
+ leds <= "10001";
+ when "01" =>
+ leds <= "01000";
+ when "10" =>
+ leds <= "00101";
+ when "11" =>
+ leds <= "00010";
+ when others =>
+ null;
+ end case;
+ when "1" =>
+ case count is
+ when "00" =>
+ leds <= "10000";
+ when "01" =>
+ leds <= "01011";
+ when "10" =>
+ leds <= "00100";
+ when "11" =>
+ leds <= "01011";
+ when others =>
+ null;
+ end case;
+ when others =>
+ null;
+ end case;
+ count := count + 1;
+ end if;
+ if clk_5sec = '1' then
+ pat_count := pat_count + 1;
+ count := "00";
+ end if;
+ end if;
+ end process;
+end multi1;
diff --git a/examples/icestick/multi2.vhdl b/examples/icestick/multi2.vhdl
new file mode 100644
index 0000000..78bf298
--- /dev/null
+++ b/examples/icestick/multi2.vhdl
@@ -0,0 +1,41 @@
+architecture multi2 of leds is
+ signal clk_4hz: std_logic;
+ signal clk_5sec : std_logic;
+begin
+ process (clk)
+ -- 3_000_000 is 0x2dc6c0
+ variable counter : unsigned (23 downto 0);
+ begin
+ if rising_edge(clk) then
+ if counter = 2_999_999 then
+ counter := x"000000";
+ clk_4hz <= '1';
+ else
+ counter := counter + 1;
+ clk_4hz <= '0';
+ end if;
+ end if;
+ end process;
+
+ process (clk)
+ variable counter5 : unsigned (4 downto 0);
+ begin
+ if rising_edge (clk) then
+ clk_5sec <= '0';
+ if clk_4hz = '1' then
+ if counter5 = 19 then
+ clk_5sec <= '1';
+ counter5 := "00000";
+ else
+ counter5 := counter5 + 1;
+ end if;
+ end if;
+ end if;
+ end process;
+
+ led1 <= clk_5sec;
+ led2 <= '0';
+ led3 <= '0';
+ led4 <= '0';
+ led5 <= '0';
+end multi2;
diff --git a/examples/icestick/rotate1.vhdl b/examples/icestick/rotate1.vhdl
new file mode 100644
index 0000000..34c7afd
--- /dev/null
+++ b/examples/icestick/rotate1.vhdl
@@ -0,0 +1,51 @@
+architecture rotate1 of leds is
+ signal clk_4hz: std_logic;
+begin
+ process (clk)
+ -- 3_000_000 is 0x2dc6c0
+ variable counter : unsigned (23 downto 0);
+ begin
+ if rising_edge(clk) then
+ if counter = 2_999_999 then
+ counter := x"000000";
+ clk_4hz <= '1';
+ else
+ counter := counter + 1;
+ clk_4hz <= '0';
+ end if;
+ end if;
+ end process;
+
+ process (clk)
+ variable count : unsigned (1 downto 0);
+ begin
+ if rising_edge(clk) and clk_4hz = '1' then
+ count := count + 1;
+ if count = 0 then
+ led1 <= '1';
+ led2 <= '0';
+ led3 <= '0';
+ led4 <= '0';
+ led5 <= '1';
+ elsif count = 1 then
+ led1 <= '0';
+ led2 <= '1';
+ led3 <= '0';
+ led4 <= '0';
+ led5 <= '0';
+ elsif count = 2 then
+ led1 <= '0';
+ led2 <= '0';
+ led3 <= '1';
+ led4 <= '0';
+ led5 <= '1';
+ else
+ led1 <= '0';
+ led2 <= '0';
+ led3 <= '0';
+ led4 <= '1';
+ led5 <= '0';
+ end if;
+ end if;
+ end process;
+end rotate1;
diff --git a/examples/icestick/rotate2.vhdl b/examples/icestick/rotate2.vhdl
new file mode 100644
index 0000000..e51ec6c
--- /dev/null
+++ b/examples/icestick/rotate2.vhdl
@@ -0,0 +1,35 @@
+architecture rotate2 of leds is
+ signal clk_4hz: std_logic;
+begin
+ process (clk)
+ -- 3_000_000 is 0x2dc6c0
+ variable counter : unsigned (23 downto 0);
+ begin
+ if rising_edge(clk) then
+ if counter = 2_999_999 then
+ counter := x"000000";
+ clk_4hz <= '1';
+ else
+ counter := counter + 1;
+ clk_4hz <= '0';
+ end if;
+ end if;
+ end process;
+
+ process (clk)
+ variable count : unsigned (1 downto 0);
+ begin
+ if rising_edge(clk) and clk_4hz = '1' then
+ count := count + 1;
+ if count = 0 then
+ (led1, led2, led3, led4, led5) <= unsigned'("10001");
+ elsif count = 1 then
+ (led1, led2, led3, led4, led5) <= unsigned'("01000");
+ elsif count = 2 then
+ (led1, led2, led3, led4, led5) <= unsigned'("00101");
+ else
+ (led1, led2, led3, led4, led5) <= unsigned'("00010");
+ end if;
+ end if;
+ end process;
+end rotate2;
diff --git a/examples/icestick/rotate3.vhdl b/examples/icestick/rotate3.vhdl
new file mode 100644
index 0000000..213512f
--- /dev/null
+++ b/examples/icestick/rotate3.vhdl
@@ -0,0 +1,38 @@
+architecture rotate3 of leds is
+ signal clk_4hz: std_logic;
+begin
+ process (clk)
+ -- 3_000_000 is 0x2dc6c0
+ variable counter : unsigned (23 downto 0);
+ begin
+ if rising_edge(clk) then
+ if counter = 2_999_999 then
+ counter := x"000000";
+ clk_4hz <= '1';
+ else
+ counter := counter + 1;
+ clk_4hz <= '0';
+ end if;
+ end if;
+ end process;
+
+ process (clk)
+ variable count : unsigned (1 downto 0);
+ begin
+ if rising_edge(clk) and clk_4hz = '1' then
+ case count is
+ when "00" =>
+ (led1, led2, led3, led4, led5) <= unsigned'("10001");
+ when "01" =>
+ (led1, led2, led3, led4, led5) <= unsigned'("01000");
+ when "10" =>
+ (led1, led2, led3, led4, led5) <= unsigned'("00101");
+ when "11" =>
+ (led1, led2, led3, led4, led5) <= unsigned'("00010");
+ when others =>
+ null;
+ end case;
+ count := count + 1;
+ end if;
+ end process;
+end rotate3;
diff --git a/examples/icestick/rotate4.vhdl b/examples/icestick/rotate4.vhdl
new file mode 100644
index 0000000..e89aaa5
--- /dev/null
+++ b/examples/icestick/rotate4.vhdl
@@ -0,0 +1,41 @@
+architecture rotate4 of leds is
+ signal clk_4hz: std_logic;
+ signal leds : std_ulogic_vector (1 to 5);
+begin
+ (led1, led2, led3, led4, led5) <= leds;
+
+ process (clk)
+ -- 3_000_000 is 0x2dc6c0
+ variable counter : unsigned (23 downto 0);
+ begin
+ if rising_edge(clk) then
+ if counter = 2_999_999 then
+ counter := x"000000";
+ clk_4hz <= '1';
+ else
+ counter := counter + 1;
+ clk_4hz <= '0';
+ end if;
+ end if;
+ end process;
+
+ process (clk)
+ variable count : unsigned (1 downto 0);
+ begin
+ if rising_edge(clk) and clk_4hz = '1' then
+ case count is
+ when "00" =>
+ leds <= "10001";
+ when "01" =>
+ leds <= "01000";
+ when "10" =>
+ leds <= "00101";
+ when "11" =>
+ leds <= "00010";
+ when others =>
+ null;
+ end case;
+ count := count + 1;
+ end if;
+ end process;
+end rotate4;
diff --git a/examples/icestick/spin1.vhdl b/examples/icestick/spin1.vhdl
new file mode 100644
index 0000000..79e305c
--- /dev/null
+++ b/examples/icestick/spin1.vhdl
@@ -0,0 +1,51 @@
+architecture spin1 of leds is
+ signal nrst : std_logic := '0';
+ signal clk_4hz: std_logic;
+ signal leds : std_ulogic_vector (1 to 5);
+begin
+ (led1, led2, led3, led4, led5) <= leds;
+
+ process (clk)
+ variable cnt : unsigned (1 downto 0) := "00";
+ begin
+ if rising_edge (clk) then
+ if cnt = 3 then
+ nrst <= '1';
+ else
+ cnt := cnt + 1;
+ end if;
+ end if;
+ end process;
+
+ process (clk)
+ -- 3_000_000 is 0x2dc6c0
+ variable counter : unsigned (23 downto 0);
+ begin
+ if rising_edge(clk) then
+ if nrst = '0' then
+ counter := x"000000";
+ else
+ if counter = 2_999_999 then
+ counter := x"000000";
+ clk_4hz <= '1';
+ else
+ counter := counter + 1;
+ clk_4hz <= '0';
+ end if;
+ end if;
+ end if;
+ end process;
+
+ process (clk)
+ begin
+ if rising_edge(clk) then
+ if nrst = '0' then
+ -- Initialize
+ leds <= "11000";
+ elsif clk_4hz = '1' then
+ -- Rotate
+ leds <= (leds (4), leds (1), leds (2), leds (3), '0');
+ end if;
+ end if;
+ end process;
+end spin1;
diff --git a/examples/icestick/spin2.vhdl b/examples/icestick/spin2.vhdl
new file mode 100644
index 0000000..0f23964
--- /dev/null
+++ b/examples/icestick/spin2.vhdl
@@ -0,0 +1,51 @@
+architecture spin1 of leds is
+ signal nrst : std_logic := '0';
+ signal clk_4hz: std_logic;
+ signal leds : std_ulogic_vector (1 to 5);
+begin
+ (led1, led2, led3, led4, led5) <= leds;
+
+ process (clk)
+ variable cnt : unsigned (1 downto 0) := "00";
+ begin
+ if rising_edge (clk) then
+ if cnt = 3 then
+ nrst <= '1';
+ else
+ cnt := cnt + 1;
+ end if;
+ end if;
+ end process;
+
+ process (clk)
+ -- 3_000_000 is 0x2dc6c0
+ variable counter : unsigned (23 downto 0);
+ begin
+ if rising_edge(clk) then
+ if nrst = '0' then
+ counter := x"000000";
+ else
+ if counter = 2_999_999 then
+ counter := x"000000";
+ clk_4hz <= '1';
+ else
+ counter := counter + 1;
+ clk_4hz <= '0';
+ end if;
+ end if;
+ end if;
+ end process;
+
+ process (clk)
+ begin
+ if rising_edge(clk) then
+ if nrst = '0' then
+ -- Initialize
+ leds <= "11000";
+ elsif clk_4hz = '1' then
+ -- Rotate
+ leds <= leds (4) & leds (1) & leds (2) & leds (3) & '0';
+ end if;
+ end if;
+ end process;
+end spin1;
diff --git a/examples/icestick/uart/README.md b/examples/icestick/uart/README.md
new file mode 100755
index 0000000..b53def6
--- /dev/null
+++ b/examples/icestick/uart/README.md
@@ -0,0 +1,11 @@
+# icestick-uart
+Simple UART sender and receiver for the lattice icestick. It echoes every received word back.
+Configuration: 115200 8N1
+
+## Repository structure
+- hdl: Contains the hardware design.
+- syn: Contains the scripts and constraints for synthesis.
+
+## Usage
+- `cd syn && ./synth.sh`
+- configure and open putty or another serial terminal and type something \ No newline at end of file
diff --git a/examples/icestick/uart/hdl/uart_rx.vhd b/examples/icestick/uart/hdl/uart_rx.vhd
new file mode 100755
index 0000000..5f488cc
--- /dev/null
+++ b/examples/icestick/uart/hdl/uart_rx.vhd
@@ -0,0 +1,66 @@
+library ieee;
+ use ieee.std_logic_1164.all;
+
+entity uart_rx is
+ generic (
+ C_BITS : integer := 8;
+ C_CYCLES_PER_BIT : integer := 104
+ );
+ port (
+ isl_clk : in std_logic;
+ isl_data_n : in std_logic;
+ oslv_data : out std_logic_vector(C_BITS-1 downto 0);
+ osl_valid : out std_logic
+ );
+end entity uart_rx;
+
+architecture rtl of uart_rx is
+ signal int_cycle_cnt : integer range 0 to C_CYCLES_PER_BIT-1 := 0;
+ signal int_bit_cnt : integer range 0 to C_BITS+1 := 0;
+
+ signal slv_data : std_logic_vector(C_BITS-1 downto 0) := (others => '0');
+ signal sl_valid : std_logic := '0';
+
+ type t_state is (IDLE, INIT, RECEIVE);
+ signal state : t_state;
+
+begin
+ process(isl_clk)
+ begin
+ if rising_edge(isl_clk) then
+ case state is
+ when IDLE =>
+ sl_valid <= '0';
+ if isl_data_n = '0' then
+ -- wait for the start bit
+ state <= INIT;
+ end if;
+
+ when INIT =>
+ int_cycle_cnt <= C_CYCLES_PER_BIT / 2;
+ int_bit_cnt <= 0;
+ state <= RECEIVE;
+
+ when RECEIVE =>
+ if int_bit_cnt < C_BITS+1 then
+ if int_cycle_cnt < C_CYCLES_PER_BIT-1 then
+ int_cycle_cnt <= int_cycle_cnt+1;
+ else
+ -- receive data bits
+ int_cycle_cnt <= 0;
+ int_bit_cnt <= int_bit_cnt+1;
+ slv_data <= not isl_data_n & slv_data(slv_data'LEFT downto 1); -- low active
+ end if;
+ elsif isl_data_n = '1' then
+ -- wait for the stop bit
+ sl_valid <= '1';
+ state <= IDLE;
+ end if;
+
+ end case;
+ end if;
+ end process;
+
+ oslv_data <= slv_data;
+ osl_valid <= sl_valid;
+end architecture rtl;
diff --git a/examples/icestick/uart/hdl/uart_top.vhd b/examples/icestick/uart/hdl/uart_top.vhd
new file mode 100755
index 0000000..889a3a0
--- /dev/null
+++ b/examples/icestick/uart/hdl/uart_top.vhd
@@ -0,0 +1,49 @@
+library ieee;
+ use ieee.std_logic_1164.all;
+
+entity uart_top is
+ generic (
+ C_BITS : integer := 8
+ );
+ port (
+ isl_clk : in std_logic;
+ isl_data_n : in std_logic;
+ osl_data_n : out std_logic;
+ osl_ready : out std_logic
+ );
+end uart_top;
+
+architecture behavioral of uart_top is
+ constant C_QUARTZ_FREQ : integer := 12000000; -- Hz
+ constant C_BAUDRATE : integer := 115200; -- words / s
+ constant C_CYCLES_PER_BIT : integer := C_QUARTZ_FREQ / C_BAUDRATE;
+
+ signal sl_valid_out_tx : std_logic := '0';
+ signal slv_data_out_tx : std_logic_vector(C_BITS-1 downto 0) := (others => '0');
+
+begin
+ i_uart_rx: entity work.uart_rx
+ generic map (
+ C_BITS => C_BITS,
+ C_CYCLES_PER_BIT => C_CYCLES_PER_BIT
+ )
+ port map (
+ isl_clk => isl_clk,
+ isl_data_n => isl_data_n,
+ oslv_data => slv_data_out_tx,
+ osl_valid => sl_valid_out_tx
+ );
+
+ i_uart_tx: entity work.uart_tx
+ generic map (
+ C_BITS => C_BITS,
+ C_CYCLES_PER_BIT => C_CYCLES_PER_BIT
+ )
+ port map (
+ isl_clk => isl_clk,
+ isl_valid => sl_valid_out_tx,
+ islv_data => slv_data_out_tx,
+ osl_data_n => osl_data_n,
+ osl_ready => osl_ready
+ );
+end behavioral; \ No newline at end of file
diff --git a/examples/icestick/uart/hdl/uart_tx.vhd b/examples/icestick/uart/hdl/uart_tx.vhd
new file mode 100755
index 0000000..b6c5800
--- /dev/null
+++ b/examples/icestick/uart/hdl/uart_tx.vhd
@@ -0,0 +1,62 @@
+library ieee;
+ use ieee.std_logic_1164.all;
+
+entity uart_tx is
+ generic (
+ -- TODO: range in submodules is not yet supported by synthesis
+ -- it would be useful to limit between 5 to 8
+ C_BITS : integer := 8;
+ C_CYCLES_PER_BIT : integer := 104
+ );
+ port (
+ isl_clk : in std_logic;
+ isl_valid : in std_logic;
+ islv_data : in std_logic_vector(C_BITS-1 downto 0);
+ osl_ready : out std_logic;
+ osl_data_n : out std_logic
+ );
+end entity uart_tx;
+
+architecture rtl of uart_tx is
+ signal int_cycle_cnt : integer range 0 to C_CYCLES_PER_BIT-1 := 0;
+ signal int_bit_cnt : integer range 0 to C_BITS+2 := 0;
+
+ signal slv_data : std_logic_vector(C_BITS downto 0) := (others => '0');
+
+ type t_state is (IDLE, INIT, SEND);
+ signal state : t_state;
+
+begin
+ process(isl_clk)
+ begin
+ if rising_edge(isl_clk) then
+ case state is
+ when IDLE =>
+ if isl_valid = '1' then
+ state <= INIT;
+ end if;
+
+ when INIT =>
+ int_cycle_cnt <= 0;
+ int_bit_cnt <= 0;
+ slv_data <= islv_data & '1';
+ state <= SEND;
+
+ when SEND =>
+ if int_cycle_cnt < C_CYCLES_PER_BIT-1 then
+ int_cycle_cnt <= int_cycle_cnt+1;
+ elsif int_bit_cnt < C_BITS+1 then
+ int_cycle_cnt <= 0;
+ int_bit_cnt <= int_bit_cnt+1;
+ slv_data <= '0' & slv_data(slv_data'LEFT downto 1);
+ else
+ state <= IDLE;
+ end if;
+
+ end case;
+ end if;
+ end process;
+
+ osl_ready <= '1' when state = IDLE else '0';
+ osl_data_n <= not slv_data(0); -- low active
+end architecture rtl; \ No newline at end of file
diff --git a/examples/icestick/uart/syn/constraints/uart.pcf b/examples/icestick/uart/syn/constraints/uart.pcf
new file mode 100755
index 0000000..e3e5016
--- /dev/null
+++ b/examples/icestick/uart/syn/constraints/uart.pcf
@@ -0,0 +1,6 @@
+# FTDI Port B UART
+set_io osl_data_n 8 # UART TX
+set_io isl_data_n 9 # UART RX
+
+# 12 MHz clock
+set_io isl_clk 21
diff --git a/examples/icestick/uart/syn/synth.sh b/examples/icestick/uart/syn/synth.sh
new file mode 100755
index 0000000..884f1b6
--- /dev/null
+++ b/examples/icestick/uart/syn/synth.sh
@@ -0,0 +1,15 @@
+set -e
+
+ROOT="$(pwd)/.."
+
+rm -rf build
+mkdir -p build
+cd build
+
+ghdl -a "$ROOT"/hdl/uart_rx.vhd
+ghdl -a "$ROOT"/hdl/uart_tx.vhd
+ghdl -a "$ROOT"/hdl/uart_top.vhd
+yosys -m ghdl -p 'ghdl uart_top; synth_ice40 -json uart_top.json'
+nextpnr-ice40 --hx1k --json uart_top.json --pcf ../constraints/uart.pcf --asc uart_top.asc --pcf-allow-unconstrained
+icepack uart_top.asc uart_top.bin
+iceprog uart_top.bin
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