Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Copyright (c) 2009 Xilinx, Inc. All rights reserved.
- *
- * Xilinx, Inc.
- * XILINX IS PROVIDING THIS DESIGN, CODE, OR INFORMATION "AS IS" AS A
- * COURTESY TO YOU. BY PROVIDING THIS DESIGN, CODE, OR INFORMATION AS
- * ONE POSSIBLE IMPLEMENTATION OF THIS FEATURE, APPLICATION OR
- * STANDARD, XILINX IS MAKING NO REPRESENTATION THAT THIS IMPLEMENTATION
- * IS FREE FROM ANY CLAIMS OF INFRINGEMENT, AND YOU ARE RESPONSIBLE
- * FOR OBTAINING ANY RIGHTS YOU MAY REQUIRE FOR YOUR IMPLEMENTATION.
- * XILINX EXPRESSLY DISCLAIMS ANY WARRANTY WHATSOEVER WITH RESPECT TO
- * THE ADEQUACY OF THE IMPLEMENTATION, INCLUDING BUT NOT LIMITED TO
- * ANY WARRANTIES OR REPRESENTATIONS THAT THIS IMPLEMENTATION IS FREE
- * FROM CLAIMS OF INFRINGEMENT, IMPLIED WARRANTIES OF MERCHANTABILITY
- * AND FITNESS FOR A PARTICULAR PURPOSE.
- *
- */
- /*
- * helloworld.c: simple test application
- */
- #include "xgpio.h" // Provides access to PB GPIO driver.
- #include <stdio.h>
- #include <stdlib.h>
- #include "mb_interface.h" // provides the microblaze interrupt enables, etc.
- #include "xintc_l.h" // Provides handy macros for the interrupt controller.
- #include "platform.h"
- #include "xparameters.h"
- #include "xaxivdma.h"
- #include "xio.h"
- #include "time.h"
- #include "unistd.h"
- #include "bitmask.h"
- #include "globals.h"
- XGpio gpLED; // This is a handle for the LED GPIO block.
- XGpio gpPB; // This is a handle for the push-button GPIO block.
- #define DEBUG
- void print(char *str);
- #define FRAME_BUFFER_0_ADDR 0xC1000000 // Starting location in DDR where we will store the images that we display.
- direction tank_direction = RIGHT;
- int move_alien_right = 1;
- u32 currentButtonState;
- u16 debounce = 0;
- u32 LEFTSBTNPRESS = 0x8;
- u32 MIDDLESBTNPRESS = 0x1;
- u32 RIGHTBTNPRESS = 0x2;
- u32 UPBTNPRESS = 0x10;
- u32 DOWNBTNPRESS = 0x4;
- u16 button_delay = 0;
- u32 update_screen_delay = 0;
- u32 second_delay = 0;
- int alien_delay_speed = 100;
- int random = 0;
- int * tankDeath_symbol;
- int tank_dead_count;
- int gameOver = 0;
- int gameOverCount;
- int UFO_speed = 0;
- int bulletShotCount = 0;
- UFO ufo;
- unsigned int * framePointer;
- void timer_interrupt_handler() {
- if (!gameOver) {
- UFO_speed++;
- button_delay++;
- update_screen_delay++;
- second_delay++;
- if (button_delay == 2) {
- button_delay = 0;
- if ((currentButtonState & LEFTSBTNPRESS) && !tank_hit) {
- //Move Tank Left
- tank_direction = LEFT;
- move_tank();
- }
- if ((currentButtonState & RIGHTBTNPRESS) && !tank_hit) {
- //Move Tank Right
- tank_direction = RIGHT;
- move_tank();
- }
- if (currentButtonState & MIDDLESBTNPRESS) {
- //Shoot Tank Bullet
- shootTankBullet();
- }
- if (currentButtonState & DOWNBTNPRESS) {
- //Make UFO
- spawnUFO();
- }
- if(currentButtonState & UPBTNPRESS)
- init(framePointer);
- }
- if (UFO_speed == 3) {
- UFO_speed = 0;
- moveUFO();
- }
- if (update_screen_delay % 128) {
- moveBullets();
- random++;
- if (random > 256) {
- shootAlienBullet();
- random = 0;
- random = rand() % 256;
- bulletShotCount++;
- }
- if(bulletShotCount == 20){
- spawnUFO();
- bulletShotCount = 0;
- }
- }
- if (second_delay == 10) {
- //updateScore(5);
- second_delay = 0;
- if (ufoDie){
- draw(ufo.pos.x, ufo.pos.y, blankAlienSymbol, ALIEN_WIDTH, ALIEN_HEIGHT,
- 0x0000000);
- ufoDie = 0;
- if(ufo.ufo_direction == RIGHT){
- ufo.ufo_direction = LEFT;
- }
- else{
- ufo.ufo_direction = RIGHT;
- }
- //add score stuff
- updateScore(69);
- }
- if (tank_hit) {
- draw(tank.x, tank.y, blankAlienSymbol, TANK_WIDTH, TANK_HEIGHT,
- 0x00000000); //clear
- draw(tank.x, tank.y, tankDeath_symbol, TANK_WIDTH, TANK_HEIGHT,
- 0x0000FF00); //draw 1
- tank_dead_count++;
- }
- if (tankDeath_symbol == tankDeath_1) {
- tankDeath_symbol = tankDeath_2;
- } else {
- tankDeath_symbol = tankDeath_1;
- }
- if (tank_dead_count == 15) {
- tank_hit = 0;
- tank_dead_count = 0;
- lives--;
- updateLives();
- draw(tank.x, tank.y, blankAlienSymbol, TANK_WIDTH, TANK_HEIGHT,
- 0x00000000); //clear
- draw(tank.x, tank.y, tankSymbol, TANK_WIDTH, TANK_HEIGHT,
- 0x000FF000); //clear
- }
- if (lives == 0) {
- int row, column;
- for (row = 0; row < 480; row++) {
- for (column = 0; column < 640; column++) {
- framePointer[row * 640 + column] = 0x00000000;
- }
- }
- int x = 175;
- int i = 0;
- int * symbol;
- for (i = 0; i < 9; i++) {
- switch (i) {
- case 0:
- symbol = GO_G;
- break;
- case 1:
- symbol = GO_A;
- break;
- case 2:
- symbol = GO_M;
- break;
- case 3:
- symbol = GO_E;
- break;
- case 4:
- symbol = GO_Blank;
- break;
- case 5:
- symbol = GO_O;
- break;
- case 6:
- symbol = GO_V;
- break;
- case 7:
- symbol = GO_E;
- break;
- case 8:
- symbol = GO_R;
- break;
- default:
- symbol = GO_G;
- }
- draw(x, 200, symbol, 32, 32, 0xFFFFFFF);
- x += 35;
- }
- gameOver = 1;
- // XGpio_InterruptClear(&gpPB, 0xFFFFFFFF); // Ack the PB interrupt.
- //XGpio_InterruptGlobalEnable(&gpPB); // Re-enable PB interrupts.
- //init(framePointer);
- }
- }
- if (update_screen_delay >= alien_delay_speed) {
- move_aliens();
- update_screen_delay = 0;
- }
- } else {
- gameOverCount++;
- if (gameOverCount == 500) {
- gameOverCount = 0;
- gameOver = 0;
- init(framePointer);
- }
- }
- }
- void pb_interrupt_handler() {
- // Clear the GPIO interrupt.
- XGpio_InterruptGlobalDisable(&gpPB); // Turn off all PB interrupts for now.
- currentButtonState = XGpio_DiscreteRead(&gpPB, 1); // Get the current state of the buttons.
- // You need to do something here.
- //xil_printf("%x\n",currentButtonState);
- XGpio_InterruptClear(&gpPB, 0xFFFFFFFF); // Ack the PB interrupt.
- XGpio_InterruptGlobalEnable(&gpPB); // Re-enable PB interrupts.
- }
- void interrupt_handler_dispatcher(void* ptr) {
- int intc_status = XIntc_GetIntrStatus(XPAR_INTC_0_BASEADDR);
- // Check the FIT interrupt first.
- if (intc_status & XPAR_FIT_TIMER_0_INTERRUPT_MASK) {
- XIntc_AckIntr(XPAR_INTC_0_BASEADDR, XPAR_FIT_TIMER_0_INTERRUPT_MASK);
- timer_interrupt_handler();
- }
- // Check the push buttons.
- if (intc_status & XPAR_PUSH_BUTTONS_5BITS_IP2INTC_IRPT_MASK) {
- XIntc_AckIntr(XPAR_INTC_0_BASEADDR, XPAR_PUSH_BUTTONS_5BITS_IP2INTC_IRPT_MASK);
- pb_interrupt_handler();
- }
- }
- int main() {
- srand(time(NULL));
- init_platform(); // Necessary for all programs.
- int Status; // Keep track of success/failure of system function calls.
- //VDMA SETUP
- XAxiVdma videoDMAController;
- // There are 3 steps to initializing the vdma driver and IP.
- // Step 1: lookup the memory structure that is used to access the vdma driver.
- XAxiVdma_Config * VideoDMAConfig = XAxiVdma_LookupConfig(
- XPAR_AXI_VDMA_0_DEVICE_ID);
- // Step 2: Initialize the memory structure and the hardware.
- if (XST_FAILURE == XAxiVdma_CfgInitialize(&videoDMAController,
- VideoDMAConfig, XPAR_AXI_VDMA_0_BASEADDR)) {
- xil_printf("VideoDMA Did not initialize.\r\n");
- }
- // Step 3: (optional) set the frame store number.
- if (XST_FAILURE == XAxiVdma_SetFrmStore(&videoDMAController, 2,
- XAXIVDMA_READ)) {
- xil_printf("Set Frame Store Failed.");
- }
- // Initialization is complete at this point.
- // Setup the frame counter. We want two read frames. We don't need any write frames but the
- // function generates an error if you set the write frame count to 0. We set it to 2
- // but ignore it because we don't need a write channel at all.
- XAxiVdma_FrameCounter myFrameConfig;
- myFrameConfig.ReadFrameCount = 2;
- myFrameConfig.ReadDelayTimerCount = 10;
- myFrameConfig.WriteFrameCount = 2;
- myFrameConfig.WriteDelayTimerCount = 10;
- Status = XAxiVdma_SetFrameCounter(&videoDMAController, &myFrameConfig);
- if (Status != XST_SUCCESS) {
- xil_printf("Set frame counter failed %d\r\n", Status);
- if (Status == XST_VDMA_MISMATCH_ERROR)
- xil_printf("DMA Mismatch Error\r\n");
- }
- // Now we tell the driver about the geometry of our frame buffer and a few other things.
- // Our image is 480 x 640.
- XAxiVdma_DmaSetup myFrameBuffer;
- myFrameBuffer.VertSizeInput = 480; // 480 vertical pixels.
- myFrameBuffer.HoriSizeInput = 640 * 4; // 640 horizontal (32-bit pixels).
- myFrameBuffer.Stride = 640 * 4; // Dont' worry about the rest of the values.
- myFrameBuffer.FrameDelay = 0;
- myFrameBuffer.EnableCircularBuf = 1;
- myFrameBuffer.EnableSync = 0;
- myFrameBuffer.PointNum = 0;
- myFrameBuffer.EnableFrameCounter = 0;
- myFrameBuffer.FixedFrameStoreAddr = 0;
- if (XST_FAILURE == XAxiVdma_DmaConfig(&videoDMAController, XAXIVDMA_READ,
- &myFrameBuffer)) {
- xil_printf("DMA Config Failed\r\n");
- }
- // We need to give the frame buffer pointers to the memory that it will use. This memory
- // is where you will write your video data. The vdma IP/driver then streams it to the HDMI
- // IP.
- myFrameBuffer.FrameStoreStartAddr[0] = FRAME_BUFFER_0_ADDR;
- myFrameBuffer.FrameStoreStartAddr[1] = FRAME_BUFFER_0_ADDR + 4 * 640 * 480;
- if (XST_FAILURE == XAxiVdma_DmaSetBufferAddr(&videoDMAController,
- XAXIVDMA_READ, myFrameBuffer.FrameStoreStartAddr)) {
- xil_printf("DMA Set Address Failed Failed\r\n");
- }
- // Print a sanity message if you get this far.
- xil_printf("Woohoo! I made it through initialization.\n\r");
- // Now, let's get ready to start displaying some stuff on the screen.
- // The variables framePointer and framePointer1 are just pointers to the base address
- // of frame 0 and frame 1.
- //unsigned int * framePointer = (unsigned int *) FRAME_BUFFER_0_ADDR;
- framePointer = (unsigned int *) FRAME_BUFFER_0_ADDR;
- // Just paint some large red, green, blue, and white squares in different
- // positions of the image for each frame in the buffer (framePointer0 and framePointer1).
- init(framePointer);
- // This tells the HDMI controller the resolution of your display (there must be a better way to do this).
- XIo_Out32(XPAR_AXI_HDMI_0_BASEADDR, 640*480);
- // Start the DMA for the read channel only.
- if (XST_FAILURE == XAxiVdma_DmaStart(&videoDMAController, XAXIVDMA_READ)) {
- xil_printf("DMA START FAILED\r\n");
- }
- int frameIndex = 0;
- // We have two frames, let's park on frame 0. Use frameIndex to index them.
- // Note that you have to start the DMA process before parking on a frame.
- if (XST_FAILURE == XAxiVdma_StartParking(&videoDMAController, frameIndex,
- XAXIVDMA_READ)) {
- xil_printf("vdma parking failed\n\r");
- }
- // Oscillate between frame 0 and frame 1.
- // int sillyTimer = MAX_SILLY_TIMER; // Just a cheap delay between frames.
- //GPIO SETUP
- int success;
- success = XGpio_Initialize(&gpPB, XPAR_PUSH_BUTTONS_5BITS_DEVICE_ID);
- // Set the push button peripheral to be inputs.
- XGpio_SetDataDirection(&gpPB, 1, 0x0000001F);
- // Enable the global GPIO interrupt for push buttons.
- XGpio_InterruptGlobalEnable(&gpPB);
- // Enable all interrupts in the push button peripheral.
- XGpio_InterruptEnable(&gpPB, 0xFFFFFFFF);
- microblaze_register_handler(interrupt_handler_dispatcher, NULL);
- XIntc_EnableIntr(XPAR_INTC_0_BASEADDR,
- (XPAR_FIT_TIMER_0_INTERRUPT_MASK | XPAR_PUSH_BUTTONS_5BITS_IP2INTC_IRPT_MASK));
- XIntc_MasterEnable(XPAR_INTC_0_BASEADDR);
- microblaze_enable_interrupts();
- while (1) {
- //char key_input = getKeyChar();
- //xil_printf("%c ", key_input);
- //processKeyPress(key_input);
- if (XST_FAILURE == XAxiVdma_StartParking(&videoDMAController, 0,
- XAXIVDMA_READ)) {
- xil_printf("vdma parking failed\n\r");
- }
- }
- cleanup_platform();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement