From 31ca140f04a6c3188376ed8230f345824f86a313 Mon Sep 17 00:00:00 2001 From: root Date: Thu, 10 Oct 2013 23:09:05 +0100 Subject: first working makefile --- .gitignore | 30 +++++++++ GPU/hdl/GPU_IF.v | 139 ++++++++++++++++++++++----------------- pong3.pin | 28 ++++---- pong3.qsf | 15 +++-- pong3.v | 2 +- software/Makefile | 60 +++++++++++++++++ software/pong3/.cproject | 60 ++++++++--------- software/pong3/pong3.c | 141 ++++++++++++++++++++++------------------ software/pong3_bsp/.cproject | 48 +++++++------- software/pong3_bsp/settings.bsp | 4 +- software/wrap.sh | 11 ++++ 11 files changed, 340 insertions(+), 198 deletions(-) create mode 100644 software/Makefile create mode 100755 software/wrap.sh diff --git a/.gitignore b/.gitignore index 7f7563f..fad1fd2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,32 @@ db pong3.qws +*.rpt +*.bak +*.pof +*.sof +incremental_db +my_sys.sopcinfo +*.done +*.fit.summary +*.jdi +*.map.summary +*.sta.summary +script/ +software/.metadata/ +software/pong3/obj/ +*~ +*.elf +*.map +*.objdump +HAL/ +alt_sys_init.c +drivers/ +libhal_bsp.a +linker.h +linker.x +mem_init.mk +memory.gdb +obj/ +public.mk +summary.html +system.h diff --git a/GPU/hdl/GPU_IF.v b/GPU/hdl/GPU_IF.v index f32de1e..16c234d 100644 --- a/GPU/hdl/GPU_IF.v +++ b/GPU/hdl/GPU_IF.v @@ -27,10 +27,10 @@ module gpuv2 #( ); - reg [9:0] ball_x; - reg [8:0] ball_y; - reg [8:0] bat0_y; - reg [8:0] bat1_y; + reg [9:0] sprite_x; + reg [9:0] sprite_y; + reg [9:0] bat0_y; + reg [9:0] bat1_y; reg [15:0] sprite[0:15]; @@ -38,18 +38,24 @@ module gpuv2 #( assign reg_addr = address[6:2]; + wire [9:0] offset; + + assign offset = 10'h80; reg [2:0] sprite_red; reg [2:0] sprite_green; reg [2:0] sprite_blue; + reg blanking; + always @(posedge clk or negedge rst_n) begin if (rst_n == 0) begin - ball_x <= 10'd127; - ball_y <= 10'd127; - bat0_y <= 10'd100; - bat1_y <= 10'd200; + blanking <= 0; + sprite_x <= 10'd127+offset; + sprite_y <= 10'd127+offset; + bat0_y <= 10'd100+offset; + bat1_y <= 10'd200+offset; sprite[0]=16'b1111111111111111; sprite[1]=16'b1000000000000001; @@ -77,15 +83,17 @@ module gpuv2 #( sprite[reg_addr[3:0]]<=data[15:0]; end else begin case (reg_addr[2:0]) - 3'b000: - ball_x <= data[9:0]; - 3'b001: - ball_y <= data[8:0]; - 3'b010: - bat0_y <= data[8:0]; - 3'b011: - bat1_y <= data[8:0]; - 3'b100: + 3'd0: + blanking <= data[0]; + 3'd1: + sprite_x <= data[9:0]; + 3'd2: + sprite_y <= data[9:0]; + 3'd3: + bat0_y <= data[9:0]; + 3'd4: + bat1_y <= data[9:0]; + 3'd5: begin sprite_red <= data[8:6]; sprite_green <= data[5:3]; @@ -110,13 +118,13 @@ module gpuv2 #( always @ (posedge vga_clk or negedge rst_n) begin if(!rst_n) - vector_x <= 10'd0; + vector_x <= offset; else if(trig_25M) begin - if(vector_x != 10'd799) - vector_x <= vector_x + 1'b1; + if(vector_x != (10'd799 + offset)) + vector_x <= vector_x + 1'b1; else - vector_x <= 10'd0; + vector_x <= offset; end end @@ -124,15 +132,15 @@ module gpuv2 #( always @ (posedge vga_clk or negedge rst_n) begin if(!rst_n) - vector_y <= 10'd0; + vector_y <= offset; else if(trig_25M) begin - if(vector_x == 10'd799) + if(vector_x == (10'd799 + offset)) begin - if(vector_y != 10'd524) + if(vector_y != (10'd524 + offset)) vector_y <= vector_y + 1'b1; else - vector_y <= 10'd0; + vector_y <= offset; end end end @@ -143,7 +151,7 @@ module gpuv2 #( vga_hs <= 1'b0; else if(trig_25M) begin - if(vector_x >= 10'd656 && vector_x < 10'd752) + if(vector_x >= (10'd656 + offset) && vector_x < (10'd752+offset)) vga_hs <= 1'b0; else vga_hs <= 1'b1; @@ -156,7 +164,7 @@ module gpuv2 #( vga_vs <= 1'b0; else if(trig_25M) begin - if(vector_y >= 10'd490 && vector_y < 10'd492) + if(vector_y >= (10'd490+offset) && vector_y < (10'd492+offset)) vga_vs <= 1'b0; else vga_vs <= 1'b1; @@ -165,52 +173,67 @@ module gpuv2 #( - reg [2:0] index; + reg px_bat; + reg px_net; + reg px_sprite; + reg px_blank; + always @ (posedge vga_clk or negedge rst_n) begin - if(!rst_n) - index <= 3'b000; - else if(trig_25M) - begin - if(vector_x < 10'd640 && vector_y < 10'd480) - if(vector_x >= (ball_x - 8 )&& vector_x <=( ball_x + 7 ) - && vector_y >= (ball_y - 8) && vector_y <= (ball_y + 7)) begin - if (sprite[(vector_y - (ball_y - 8)) & 15 ][(vector_x - (ball_x -8))& 15 ]) - index <= 3'b001; - else - index <= 3'b000; - end else if (vector_x < 10'd4) - if (vector_y >=( bat0_y - 20 ) && vector_y <= (bat0_y + 20) ) - index <= 3'b111; - else - index <= 3'b000; - else if (vector_x >= 10'd318 && vector_x < 10'd322) - index <= {3{vector_y[3]}}; - else if (vector_x >= 10'd636 && vector_x < 10'd640) - if (vector_y >=( bat1_y - 20 ) && vector_y <= (bat1_y + 20) ) - index <= 3'b111; - else - index <= 3'b000; - else - index <= 3'b000; - else - index <= 3'b000; + if(!rst_n) begin + px_bat <= 0; + px_net <= 0; + px_sprite <= 0; + px_blank <= 1; + end else if(trig_25M) begin + if(vector_x>= offset && vector_x < (10'd640+offset) && vector_y >= offset && vector_y < (10'd480+offset)) + px_blank<= blanking; + else + px_blank<=1; + + if(vector_x >= (sprite_x - 8 )&& vector_x <=( sprite_x + 7 ) + && vector_y >= (sprite_y - 8) && vector_y <= (sprite_y + 7)) + px_sprite <= sprite[(vector_y - (sprite_y - 8)) & 15 ][(vector_x - (sprite_x -8))& 15 ]; + else + px_sprite <= 0; + + if (vector_x < (10'd4+offset) && vector_y >=( bat0_y - 20 ) && vector_y <= (bat0_y + 20) ) + px_bat <= 1; + else if (vector_x >= (10'd636 + offset) && vector_y >=( bat1_y - 20 ) && vector_y <= (bat1_y + 20) ) + px_bat <=1 ; + else + px_bat <=0; + + + if (vector_x >= (10'd318 +offset) && vector_x < (10'd322+offset)) + px_net <= {3{vector_y[3]}}; + else + px_net <= 0; + end end always begin - if (index == 3'b000) begin + if (px_blank) begin vga_red = 3'b000; vga_green = 3'b000; vga_blue = 3'b000; - end else if (index == 3'b001) begin + end else if (px_bat) begin + vga_red= 3'b111; + vga_green=3'b111; + vga_blue=3'b111; + end else if (px_sprite) begin vga_red = sprite_red; vga_green= sprite_green; vga_blue = sprite_blue; - end else begin + end else if (px_net) begin vga_red= 3'b111; vga_green=3'b111; vga_blue=3'b111; + end else begin + vga_red = 3'b000; + vga_green = 3'b000; + vga_blue = 3'b000; end diff --git a/pong3.pin b/pong3.pin index 0c00d27..d658730 100644 --- a/pong3.pin +++ b/pong3.pin @@ -97,17 +97,17 @@ GND* : 30 : : : GND* : 31 : : : : 1 : VCCINT : 32 : power : : 1.2V : : GND* : 33 : : : : 1 : -GND* : 34 : : : : 1 : -seven_seg[2] : 35 : output : 3.3-V LVTTL : : 1 : N +seven_seg[0] : 34 : output : 3.3-V LVTTL : : 1 : Y +seven_seg[1] : 35 : output : 3.3-V LVTTL : : 1 : Y GND : 36 : gnd : : : : -GND* : 37 : : : : 1 : +seven_seg[5] : 37 : output : 3.3-V LVTTL : : 1 : Y GND : 38 : gnd : : : : -GND* : 39 : : : : 1 : -GND* : 40 : : : : 1 : +seven_seg[2] : 39 : output : 3.3-V LVTTL : : 1 : Y +seven_seg[6] : 40 : output : 3.3-V LVTTL : : 1 : Y GND* : 41 : : : : 1 : VCCIO1 : 42 : power : : 3.3V : 1 : -GND* : 43 : : : : 1 : -seven_seg[3] : 44 : output : 3.3-V LVTTL : : 1 : N +seven_seg[4] : 43 : output : 3.3-V LVTTL : : 1 : Y +seven_seg[3] : 44 : output : 3.3-V LVTTL : : 1 : Y sdram_cs_n : 45 : output : 3.3-V LVTTL : : 1 : Y sdram_cke : 46 : output : 3.3-V LVTTL : : 1 : Y sdram_clk : 47 : output : 3.3-V LVTTL : : 1 : Y @@ -169,11 +169,11 @@ sdram_dq[9] : 102 : bidir : 3.3-V LVTTL : sdram_dq[8] : 103 : bidir : 3.3-V LVTTL : : 4 : Y sdram_dqm[1] : 104 : output : 3.3-V LVTTL : : 4 : Y GND* : 105 : : : : 3 : -seven_seg[6] : 106 : output : 3.3-V LVTTL : : 3 : N -seven_seg[0] : 107 : output : 3.3-V LVTTL : : 3 : N +GND* : 106 : : : : 3 : +GND* : 107 : : : : 3 : vga_red[0] : 108 : output : 3.3-V LVTTL : : 3 : Y VCCIO3 : 109 : power : : 3.3V : 3 : -seven_seg[5] : 110 : output : 3.3-V LVTTL : : 3 : N +GND* : 110 : : : : 3 : GND : 111 : gnd : : : : vga_red[2] : 112 : output : 3.3-V LVTTL : : 3 : Y vga_red[1] : 113 : output : 3.3-V LVTTL : : 3 : Y @@ -236,7 +236,7 @@ GND* : 169 : : : GND* : 170 : : : : 2 : GND* : 171 : : : : 2 : VCCIO2 : 172 : power : : 3.3V : 2 : -GND* : 173 : : : : 2 : +seven_seg[7] : 173 : output : 3.3-V LVTTL : : 2 : N GND : 174 : gnd : : : : GND* : 175 : : : : 2 : GND* : 176 : : : : 2 : @@ -258,17 +258,17 @@ GND* : 191 : : : GND* : 192 : : : : 2 : GND* : 193 : : : : 2 : VCCIO2 : 194 : power : : 3.3V : 2 : -seven_seg[1] : 195 : output : 3.3-V LVTTL : : 2 : N +GND* : 195 : : : : 2 : GND : 196 : gnd : : : : GND* : 197 : : : : 2 : GND* : 198 : : : : 2 : GND* : 199 : : : : 2 : GND* : 200 : : : : 2 : -seven_seg[4] : 201 : output : 3.3-V LVTTL : : 2 : N +GND* : 201 : : : : 2 : VCCIO2 : 202 : power : : 3.3V : 2 : GND* : 203 : : : : 2 : GND : 204 : gnd : : : : -seven_seg[7] : 205 : output : 3.3-V LVTTL : : 2 : N +GND* : 205 : : : : 2 : GND* : 206 : : : : 2 : GND* : 207 : : : : 2 : GND* : 208 : : : : 2 : diff --git a/pong3.qsf b/pong3.qsf index 0523c4d..f8ef54f 100644 --- a/pong3.qsf +++ b/pong3.qsf @@ -48,13 +48,13 @@ set_global_assignment -name DEVICE_FILTER_PACKAGE "ANY QFP" set_global_assignment -name DEVICE_FILTER_PIN_COUNT 208 set_global_assignment -name DEVICE_FILTER_SPEED_GRADE 8 set_global_assignment -name ERROR_CHECK_FREQUENCY_DIVISOR 1 -set_location_assignment PIN_40 -to seg[6] -set_location_assignment PIN_37 -to seg[5] -set_location_assignment PIN_43 -to seg[4] -set_location_assignment PIN_44 -to seg[3] -set_location_assignment PIN_39 -to seg[2] -set_location_assignment PIN_35 -to seg[1] -set_location_assignment PIN_34 -to seg[0] +set_location_assignment PIN_40 -to seven_seg[6] +set_location_assignment PIN_37 -to seven_seg[5] +set_location_assignment PIN_43 -to seven_seg[4] +set_location_assignment PIN_44 -to seven_seg[3] +set_location_assignment PIN_39 -to seven_seg[2] +set_location_assignment PIN_35 -to seven_seg[1] +set_location_assignment PIN_34 -to seven_seg[0] set_location_assignment PIN_23 -to clk set_location_assignment PIN_27 -to rst_n set_location_assignment PIN_92 -to sdram_addr[12] @@ -148,4 +148,5 @@ set_global_assignment -name PIN_FILE pong3.pin set_global_assignment -name VERILOG_FILE pong3.v set_global_assignment -name QSYS_FILE my_sys.qsys + set_instance_assignment -name PARTITION_HIERARCHY root_partition -to | -section_id Top \ No newline at end of file diff --git a/pong3.v b/pong3.v index 0328dcc..0ad6803 100644 --- a/pong3.v +++ b/pong3.v @@ -85,7 +85,7 @@ module pong3( .sdram_0_wire_dqm (sdram_dqm ), .sdram_0_wire_ras_n(sdram_ras_n), .sdram_0_wire_we_n (sdram_we_n ), - .pio_0_d_export (SEG ), + .pio_0_d_export (seven_seg ), .gpu_0_vga_red(vga_red), diff --git a/software/Makefile b/software/Makefile new file mode 100644 index 0000000..13116c7 --- /dev/null +++ b/software/Makefile @@ -0,0 +1,60 @@ +# +# + +ELFDIR=../software/pong3 +BSPDIR=../software/pong3_bsp +ELF=pong3.elf + +SOPCINFO=../my_sys.sopcinfo +SOF=../pong3.sof + +run: load_elf.stamp + ./wrap.sh nios2-terminal + +flash: load_sof.stamp sof.flash elf.flash ${BSPDIR}/system.h + BASE=` grep EPCS_FLASH_CONTROLLER_0_BASE ${BSPDIR}/system.h | awk '{print $$3}' ` && \ + ./wrap.sh nios2-flash-programmer sof.flash --base=$${BASE} --epcs --accept-bad-sysid --device=1 --instance=0 --program --verbose && \ + ./wrap.sh nios2-flash-programmer elf.flash --base=$${BASE} --epcs --accept-bad-sysid --device=1 --instance=0 --program --verbose -g + +sof.flash: ${SOF} + ./wrap.sh sof2flash --input=$< --output=$@ --epcs --verbose + +elf.flash: ${ELFDIR}/${ELF} sof.flash + ./wrap.sh elf2flash --input=${ELFDIR}/${ELF} --output=$@ --epcs --after=sof.flash --verbose + + + + + + + +load_elf.stamp:load_sof.stamp ${ELFDIR}/${ELF} + ./wrap.sh nios2-download ${ELFDIR}/${ELF} -g + +load_sof.stamp: ${SOF} + ./wrap.sh quartus_pgm -m JTAG -o 'p;../pong3.sof' + +${ELFDIR}/${ELF}: ${BSPDIR}/libhal_bsp.a + ./wrap.sh ${MAKE} -C ${ELFDIR} + + +${BSPDIR}/libhal_bsp.a:${BSPDIR}/system.h + ./wrap.sh ${MAKE} -C ${BSPDIR} + +${BSPDIR}/system.h:${SOPCINFO} + rm -f $@ + (cd ${BSPDIR} && ${PWD}/wrap.sh ./create-this-bsp ) + + +clean: + ./wrap.sh ${MAKE} -C ${BSPDIR} clean + ./wrap.sh ${MAKE} -C ${ELFDIR} clean + /bin/rm -f sof.flash elf.flash + /bin/rm -rf ${BSPDIR}/drivers ${BSPDIR}/HAL ${BSPDIR}/linker.h ${BSPDIR}/linker.x ${BSPDIR}/system.h ${BSPDIR}/summary.html ${BSPDIR}/public.mk ${BSPDIR}/mem_init.mk ${BSPDIR}/memory.gdb ${BSPDIR}/alt_sys_init.c + + + + + + + diff --git a/software/pong3/.cproject b/software/pong3/.cproject index ae6d1bc..f15f89f 100644 --- a/software/pong3/.cproject +++ b/software/pong3/.cproject @@ -3,19 +3,19 @@ - - + + - + - - - - - - - - - + @@ -313,32 +313,32 @@ - + - - - + + + - + - - - + + + - + diff --git a/software/pong3/pong3.c b/software/pong3/pong3.c index 63ae56c..0e88ac8 100644 --- a/software/pong3/pong3.c +++ b/software/pong3/pong3.c @@ -13,59 +13,12 @@ gpu_write (unsigned int reg, unsigned int data) IOWR (GPU_0_BASE, reg << 2, data); } -static int -find_intersection (int x, int y, int xd, int yd, int t) -{ - - // super lazy - we should use the power of MATHS - - while (x != t) - { - x += xd; - y += yd; - - if (y < 0) - y = 0; - if (y > 479) - y = 479; - if ((y == 479) || (y == 0)) - yd = -yd; - - if ((x == 639) || (x == 0)) - xd = -xd; - } - - return y; -} - -static int -dir (int a, int b) -{ - if (a > b) - return 1; - if (a < b) - return -1; - return 0; -} - -static void -move_bat (int *b, int db) -{ - - *b += dir (db, *b); - if (*b < 20) - *b = 20; - if (*b > 459) - *b = 459; - -} - static void load_sprite (void) { // RRR GGG BBB // set the sprite color 111 010 000 - orange - gpu_write (4, 0x01D0); + gpu_write (5, 0x01D0); // squirt the bromium logo into the sprite gpu_write (0x10, 0x00C0); @@ -86,6 +39,60 @@ load_sprite (void) gpu_write (0x1f, 0x00C0); } + +static int +dir (int a, int b) +{ + if (a > b) + return 1; + if (a < b) + return -1; + return 0; +} + +static void +move_bat (int *b, int db) +{ + *b += dir (db, *b); +} + +static int +squish (int *v, int min, int max) +{ + if (*v < min) + { + *v = min; + return 1; + } + if (*v >= max) + { + *v = max - 1; + return 1; + } + return 0; +} + +static int +find_intersection (int x, int y, int xd, int yd, int t) +{ + + // super lazy - we should use the power of MATHS + + while (x != t) + { + x += xd; + y += yd; + + if (squish (&y, 0, 480)) + yd = -yd; + + if (squish (&x, 0, 640)) + xd = -xd; + } + + return y; +} + int main (void) { @@ -117,35 +124,45 @@ main (void) { x += xd; y += yd; - if (y < 0) - y = 0; - if (y > 479) - y = 479; - if ((y == 479) || (y == 0)) + + + if (squish (&y, 0, 480)) yd = -yd; - if ((x == 639) || (x == 0)) + if (squish (&x, 0, 640)) { - xd = -xd; + xd = (rand () % 3) + 1; + if (x) + xd = -xd; yd = rand () % 7; yd -= 3; - dbat0 = find_intersection (x + xd, y + yd, xd, yd, 0); - dbat1 = find_intersection (x + xd, y + yd, xd, yd, 639); + + if (x) + { + dbat0 = find_intersection (x + xd, y + yd, xd, yd, 0); + dbat1 = 480 / 2; + } + else + { + dbat0 = 480 / 2; + + dbat1 = find_intersection (x + xd, y + yd, xd, yd, 639); + } } move_bat (&bat0, dbat0); move_bat (&bat1, dbat1); - gpu_write (0, x); - gpu_write (1, y); + gpu_write (1, x + 0x80); + gpu_write (2, y + 0x80); + gpu_write (3, bat0 + 0x80); + gpu_write (4, bat1 + 0x80); - gpu_write (2, bat0); - gpu_write (3, bat1); + gpu_write (0, 0); msleep (2); } } } -//------------------------------------------------------------------------- diff --git a/software/pong3_bsp/.cproject b/software/pong3_bsp/.cproject index bca629e..aaab98e 100644 --- a/software/pong3_bsp/.cproject +++ b/software/pong3_bsp/.cproject @@ -3,19 +3,19 @@ - - + + - + - - - - - - - - - + @@ -313,12 +313,12 @@ - + - + @@ -331,7 +331,7 @@ - + diff --git a/software/pong3_bsp/settings.bsp b/software/pong3_bsp/settings.bsp index e567b80..6bafac0 100644 --- a/software/pong3_bsp/settings.bsp +++ b/software/pong3_bsp/settings.bsp @@ -2,8 +2,8 @@ hal default - Oct 10, 2013 11:49:08 AM - 1381402148374 + Oct 10, 2013 11:06:28 PM + 1381442788161 /home/root/projects/altera/pong3/software/pong3_bsp ./settings.bsp ../../my_sys.sopcinfo diff --git a/software/wrap.sh b/software/wrap.sh new file mode 100755 index 0000000..4caed0f --- /dev/null +++ b/software/wrap.sh @@ -0,0 +1,11 @@ +#!/bin/sh + +AD=/software/apps/altera/quartus_ii_13.0sp1 +LL=linux +QUARTUS_ROOTDIR="${AD}/quartus" +PATH="${AD}/quartus/bin:${AD}/nios2eds/sdk2/bin:${AD}/nios2eds/bin:${AD}/nios2eds/bin/gnu/H-i686-pc-linux-gnu/bin:${PATH}" +LD_LIBRARY_PATH="${AD}/quartus/${LL}:${LD_LIBRARY_PATH}" + +export LD_LIBRARY_PATH PATH QUARTUS_ROOTDIR + +"$@" -- cgit v1.2.3