aboutsummaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/up5k_mac16/.gitignore12
-rw-r--r--examples/up5k_mac16/mac16.pcf4
-rw-r--r--examples/up5k_mac16/mac16.v71
-rw-r--r--examples/up5k_rgb/.gitignore12
-rw-r--r--examples/up5k_rgb/Makefile36
-rw-r--r--examples/up5k_rgb/rgb.pcf3
-rw-r--r--examples/up5k_rgb/rgb.v81
7 files changed, 219 insertions, 0 deletions
diff --git a/examples/up5k_mac16/.gitignore b/examples/up5k_mac16/.gitignore
new file mode 100644
index 0000000..dd32bfb
--- /dev/null
+++ b/examples/up5k_mac16/.gitignore
@@ -0,0 +1,12 @@
+*.bin
+*.blif
+*.asc
+*.rpt
+*.glb
+*.psb
+*.sdf
+*.vsb
+*.bin
+*.tmp/
+*.exp
+*.vlog
diff --git a/examples/up5k_mac16/mac16.pcf b/examples/up5k_mac16/mac16.pcf
new file mode 100644
index 0000000..24b9b45
--- /dev/null
+++ b/examples/up5k_mac16/mac16.pcf
@@ -0,0 +1,4 @@
+set_io clk 44
+set_io rstn 27
+set_io LED1 12
+set_io LED2 13 \ No newline at end of file
diff --git a/examples/up5k_mac16/mac16.v b/examples/up5k_mac16/mac16.v
new file mode 100644
index 0000000..73740e3
--- /dev/null
+++ b/examples/up5k_mac16/mac16.v
@@ -0,0 +1,71 @@
+module top(
+ input clk,
+ input rstn,
+ output LED1,
+ output LED2);
+
+wire reset = !rstn;
+
+wire [15:0] A = 16'd999;
+wire [15:0] B = 16'd12345;
+wire [31:0] RES = 32'd12332655;
+
+wire [31:0] dsp_out;
+
+SB_MAC16 i_sbmac16
+ (
+ .A(A),
+ .B(B),
+ .C(16'b0),
+ .D(16'b0),
+ .CLK(clk),
+ .CE(1'b1),
+ .IRSTTOP(reset),
+ .IRSTBOT(reset),
+ .ORSTTOP(reset),
+ .ORSTBOT(reset),
+ .AHOLD(1'b0),
+ .BHOLD(1'b0),
+ .CHOLD(1'b0),
+ .DHOLD(1'b0),
+ .OHOLDTOP(1'b0),
+ .OHOLDBOT(1'b0),
+ .OLOADTOP(1'b0),
+ .OLOADBOT(1'b0),
+ .ADDSUBTOP(1'b0),
+ .ADDSUBBOT(1'b0),
+ .CO(),
+ .CI(1'b0),
+ .O(dsp_out)
+ );
+
+//16x16 => 32 unsigned pipelined multiply
+defparam i_sbmac16. B_SIGNED = 1'b0;
+defparam i_sbmac16. A_SIGNED = 1'b0;
+defparam i_sbmac16. MODE_8x8 = 1'b0;
+
+defparam i_sbmac16. BOTADDSUB_CARRYSELECT = 2'b00;
+defparam i_sbmac16. BOTADDSUB_UPPERINPUT = 1'b0;
+defparam i_sbmac16. BOTADDSUB_LOWERINPUT = 2'b00;
+defparam i_sbmac16. BOTOUTPUT_SELECT = 2'b11;
+
+defparam i_sbmac16. TOPADDSUB_CARRYSELECT = 2'b00;
+defparam i_sbmac16. TOPADDSUB_UPPERINPUT = 1'b0;
+defparam i_sbmac16. TOPADDSUB_LOWERINPUT = 2'b00;
+defparam i_sbmac16. TOPOUTPUT_SELECT = 2'b11;
+
+defparam i_sbmac16. PIPELINE_16x16_MULT_REG2 = 1'b1;
+defparam i_sbmac16. PIPELINE_16x16_MULT_REG1 = 1'b1;
+defparam i_sbmac16. BOT_8x8_MULT_REG = 1'b1;
+defparam i_sbmac16. TOP_8x8_MULT_REG = 1'b1;
+defparam i_sbmac16. D_REG = 1'b0;
+defparam i_sbmac16. B_REG = 1'b1;
+defparam i_sbmac16. A_REG = 1'b1;
+defparam i_sbmac16. C_REG = 1'b0;
+
+assign LED1 = (dsp_out == RES) ? 1'b1 : 1'b0;
+assign LED2 = 1'b0;
+
+
+
+endmodule \ No newline at end of file
diff --git a/examples/up5k_rgb/.gitignore b/examples/up5k_rgb/.gitignore
new file mode 100644
index 0000000..dd32bfb
--- /dev/null
+++ b/examples/up5k_rgb/.gitignore
@@ -0,0 +1,12 @@
+*.bin
+*.blif
+*.asc
+*.rpt
+*.glb
+*.psb
+*.sdf
+*.vsb
+*.bin
+*.tmp/
+*.exp
+*.vlog
diff --git a/examples/up5k_rgb/Makefile b/examples/up5k_rgb/Makefile
new file mode 100644
index 0000000..711ce5a
--- /dev/null
+++ b/examples/up5k_rgb/Makefile
@@ -0,0 +1,36 @@
+PROJ = rgb
+PIN_DEF = rgb.pcf
+DEVICE = up5k
+# Relative paths for easier development without messing with installed version
+ARACHNE = ../../../arachne-pnr/bin/arachne-pnr
+ARACHNE_ARGS = -c ../../icebox/chipdb-5k.txt
+ICEPACK = ../../icepack/icepack
+ICETIME = ../../icetime/icetime
+ICEPROG = ../../iceprog/iceprog
+
+all: $(PROJ).bin
+
+%.blif: %.v
+ yosys -p 'synth_ice40 -top top -blif $@' $<
+
+%.asc: $(PIN_DEF) %.blif
+ $(ARACHNE) $(ARACHNE_ARGS) -d $(subst up,,$(subst hx,,$(subst lp,,$(DEVICE)))) -o $@ -p $^
+
+%.bin: %.asc
+ $(ICEPACK) $< $@
+
+%.rpt: %.asc
+ $(ICETIME) -d $(DEVICE) -mtr $@ $<
+
+prog: $(PROJ).bin
+ $(ICEPROG) -S $<
+
+sudo-prog: $(PROJ).bin
+ @echo 'Executing prog as root!!!'
+ sudo $(ICEPROG) -S $<
+
+clean:
+ rm -f $(PROJ).blif $(PROJ).asc $(PROJ).rpt $(PROJ).bin
+
+.SECONDARY:
+.PHONY: all prog clean
diff --git a/examples/up5k_rgb/rgb.pcf b/examples/up5k_rgb/rgb.pcf
new file mode 100644
index 0000000..cfdb874
--- /dev/null
+++ b/examples/up5k_rgb/rgb.pcf
@@ -0,0 +1,3 @@
+set_io RGB0 39
+set_io RGB1 40
+set_io RGB2 41 \ No newline at end of file
diff --git a/examples/up5k_rgb/rgb.v b/examples/up5k_rgb/rgb.v
new file mode 100644
index 0000000..c83b943
--- /dev/null
+++ b/examples/up5k_rgb/rgb.v
@@ -0,0 +1,81 @@
+module top(
+ output RGB0, RGB1, RGB2
+);
+
+wire clk;
+
+SB_HFOSC inthosc (
+ .CLKHFPU(1'b1),
+ .CLKHFEN(1'b1),
+ .CLKHF(clk)
+);
+
+localparam counter_width = 30;
+
+reg [counter_width-1:0] ctr;
+
+always@(posedge clk)
+begin
+ ctr <= ctr + 1;
+end
+
+localparam pwm_width = 12;
+
+localparam pwm_max = (2**pwm_width) - 1;
+localparam pwm_max_div4 = (2**(pwm_width-2)) - 1;
+
+
+wire [1:0] phase = ctr[counter_width - 1 : counter_width - 2];
+wire [pwm_width-1:0] fade = ctr[counter_width - 3 : counter_width - (2 + pwm_width)];
+wire [pwm_width-1:0] fade_div4 = ctr[counter_width - 3 : counter_width - (pwm_width)];
+
+wire [pwm_width-1:0] r_val, g_val, b_val;
+
+// Fade R->G->B->W->
+assign r_val = (phase == 0) ? pwm_max_div4 + (3 * fade_div4) :
+ (phase == 1) ? pwm_max - fade :
+ (phase == 3) ? fade_div4 :
+ 0;
+
+assign g_val = (phase == 0) ? pwm_max_div4 - fade_div4:
+ (phase == 1) ? fade :
+ (phase == 2) ? pwm_max - fade :
+ (phase == 3) ? fade_div4 :
+ 0;
+
+assign b_val = (phase == 0) ? pwm_max_div4 - fade_div4:
+ (phase == 2) ? fade :
+ (phase == 3) ? pwm_max - (3 * fade_div4) :
+ 0;
+
+reg [pwm_width-1:0] pwm_ctr;
+
+reg pwm_r, pwm_g, pwm_b;
+
+always@(posedge clk)
+begin
+ pwm_ctr <= pwm_ctr + 1;
+ pwm_r <= (pwm_ctr < r_val) ? 1'b1 : 1'b0;
+ pwm_g <= (pwm_ctr < g_val) ? 1'b1 : 1'b0;
+ pwm_b <= (pwm_ctr < b_val) ? 1'b1 : 1'b0;
+end
+
+SB_RGBA_DRV RGBA_DRIVER (
+ .CURREN(1'b1),
+ .RGBLEDEN(1'b1),
+ .RGB0PWM(pwm_g),
+ .RGB1PWM(pwm_b),
+ .RGB2PWM(pwm_r),
+ .RGB0(RGB0),
+ .RGB1(RGB1),
+ .RGB2(RGB2)
+);
+
+
+defparam RGBA_DRIVER.CURRENT_MODE = "0b1";
+defparam RGBA_DRIVER.RGB0_CURRENT = "0b000001";
+defparam RGBA_DRIVER.RGB1_CURRENT = "0b000011";
+defparam RGBA_DRIVER.RGB2_CURRENT = "0b000011";
+
+
+endmodule \ No newline at end of file