/* cons_init - initializes the console devices */ void cons_init(void) { //int ctl = IORD(JTAG_UART_CONTROL, 0); IOWR(JTAG_UART_CONTROL, 0, 1); alt_irq_enable(JTAG_UART_IRQ); }
/** This function is a re-implementation of the Altera provided function. * The function is re-implemented to prevent it from enabling an interrupt * when it is registered. Interrupts should only be enabled after the FreeRTOS.org * kernel has its scheduler started so that contexts are saved and switched * correctly. */ int alt_irq_register( alt_u32 id, void* context, void (*handler)(void*, alt_u32) ) { int rc = -EINVAL; alt_irq_context status; if (id < ALT_NIRQ) { /* * interrupts are disabled while the handler tables are updated to ensure * that an interrupt doesn't occur while the tables are in an inconsistent * state. */ status = alt_irq_disable_all (); alt_irq[id].handler = handler; alt_irq[id].context = context; rc = (handler) ? alt_irq_enable (id): alt_irq_disable (id); /* alt_irq_enable_all(status); This line is removed to prevent the interrupt from being immediately enabled. */ } return rc; }
void playCongrat() { // register isr sound_data_counter = 0; alt_irq_register(AUDIO_IRQ, 0x0, congrat_isr); // enable interrupt alt_irq_enable(AUDIO_IRQ); alt_up_audio_enable_write_interrupt(audio_dev); }
//Starts hardware timer void start_timer() { printf("Starting Timer\n"); alt_irq_enable(TIMER_0_IRQ); IOWR_16DIRECT(TIMER_0_BASE, 4, 7); /* int control; control = IORD_16DIRECT(TIMER_0_BASE, 4); printf("New control (2): %x\n", control); */ }
/** * Initiating UART Core with: * 115200 Baudrate * refer to /documentation/n2cpu_nii51010.pdf for more info */ void diverInitUART(int baud) { //Each Bit in the control register enables an IRQ for a corresponding bit in the status register. int control = ALTERA_AVALON_UART_CONTROL_RRDY_MSK | //enable Read Interrupts ALTERA_AVALON_UART_CONTROL_E_MSK; //enable Exceptions for each Interrupt IOWR_ALTERA_AVALON_UART_CONTROL(UART_0_BASE, control); //write contorl bitmask in the control register IOWR_ALTERA_AVALON_UART_STATUS(UART_0_BASE, 0x00); //writing 0 in the status Register clears the dcts,e,toe,roe,brk,fe, and pe bits //writing up the Baudrate-divisor //setting Baudrate-divisor: div = clk / desired Baudrate + 0,5 int divisor = (int) (50000000 / baud + 0.5); //div will be 434 IOWR_ALTERA_AVALON_UART_DIVISOR(UART_0_BASE, divisor); //install IRQ service routine alt_irq_register(UART_0_IRQ, 0, (alt_isr_func) ISRUART); alt_irq_enable(UART_0_IRQ); }
void serial_init(unsigned int baud) { //inhibit all UART IRQ sources IOWR(UART_0_BASE, 3, 0x00); //set Baud rate IOWR(UART_0_BASE, 4, baud); //flush any characters sitting in the holding register IORD(UART_0_BASE, 0); IORD(UART_0_BASE, 0); //reset most of the status register bits IOWR(UART_0_BASE, 2, 0x00); //install IRQ service routine alt_irq_register(UART_0_IRQ, 0, serial_irq_0); alt_irq_enable(UART_0_IRQ); //enable irq for Rx. IOWR(UART_0_BASE, 3, 0x0080); }
/* The main function creates two task and starts multi-tasking */ int main(void) { OSInit(); // Create the message queue to hold incoming MIDI msg qsemMsg = OSQCreate((void*)&qMessages, QMESSAGE_SIZE); songSem = OSSemCreate(0); lcd = fopen("/dev/char_lcd", "w"); //Task for decoding MIDI messages. OSTaskCreateExt(midiDecode, NULL, (void *)&midi_stk[TASK_STACKSIZE-1], MIDI_PRIORITY, MIDI_PRIORITY, midi_stk, TASK_STACKSIZE, NULL, 0); serial_init(31250); /* Enable all 8 switch interrupts. */ IOWR_ALTERA_AVALON_PIO_IRQ_MASK(SWITCHES_BASE, 0xff); /* Reset the edge capture register. */ IOWR_ALTERA_AVALON_PIO_EDGE_CAP(SWITCHES_BASE, 0x0); /* Register the interrupt handler. */ alt_irq_register(SWITCHES_IRQ, 0, switches_isr); alt_irq_enable(SWITCHES_IRQ); OSTaskCreateExt(playSong, NULL, (void *)&song_stk[TASK_STACKSIZE-1], SONG_PRIORITY, SONG_PRIORITY, song_stk, TASK_STACKSIZE, NULL, 0); OSStart(); return 0; }
/* * Main Game Loop */ int main() { // Use the name of your pixel buffer DMA core pixel_buffer =alt_up_pixel_buffer_dma_open_dev("/dev/pixel_buffer_dma_0"); initVGA(); usleep(5000000); ps2 = alt_up_ps2_open_dev("/dev/ps2_0"); ps2->timeout = 2000000; alt_up_ps2_clear_fifo(ps2); alt_up_ps2_init(ps2); unsigned char byte1; while(alt_up_ps2_read_data_byte(ps2, &byte1)!=0); char_lcd_dev = alt_up_character_lcd_open_dev ("/dev/character_lcd_0"); alt_up_character_lcd_init (char_lcd_dev); char_buffer = alt_up_char_buffer_open_dev("/dev/char_drawer"); alt_up_char_buffer_init(char_buffer); alt_up_sd_card_dev *device_reference = NULL; struct Env* p = initEnv(); initGameInfo(); struct Collidable* collisionChecker = initCollidable(); addCollisionToEnv(p, collisionChecker); promptSDcard(p, device_reference); usleep(1000); alt_up_char_buffer_string(char_buffer, "Loading ", 40, 30); unsigned end_time, start_time; int count = 0; lock = 0; struct animation* starAnimation = loadSDImageSeq("ST0.BMP", 2, 8); struct animation* star2Animation = loadSDImageSeq("ST00.BMP", 3, 7); struct animation* alien0 = loadSDImageSeq("A100.BMP", 2, 2); //2 images where first 2 characters are prefix struct animation* alien1 = loadSDImageSeq("A000.BMP", 2, 15); struct animation* ship0 = loadSDImageSeq("S00.BMP", 2, 16); struct animation* ship1 = loadSDImageSeq("S10.BMP", 2, 27); struct animation* bossAnimate = loadSDImageSeq("BO00.BMP", 2, 28); struct animation* ship2 = loadSDImageSeq("S20.BMP", 2, 35); struct animation* ship3 = loadSDImageSeq("S30.BMP", 2, 30); struct animation* ship4 = loadSDImageSeq("S40.BMP", 2, 10); struct animation* explode1 = initAnimation((int*)explode01, 1); addImage(explode1, initAnimation((int*)explode02, 0)); addImage(explode1, initAnimation((int*)explode03, 0)); addImage(explode1, initAnimation((int*)explode04, 0)); addImage(explode1, initAnimation((int*)explode05, 0)); struct animation** shipAnimationCollection = (struct animation**)malloc(sizeof(struct animation*)*5); shipAnimationCollection[0] = ship0; shipAnimationCollection[1] = ship1; shipAnimationCollection[2] = ship2; shipAnimationCollection[3] = ship3; shipAnimationCollection[4] = ship4; initWeapon(collisionChecker, p); struct Cursor* mouse = initCursor(p, collisionChecker); addToEnv(p, mouse->super); addObjToCollide(collisionChecker, mouse->super); setCursor(p, mouse); struct KeyController* keyController = initKeyController(); struct SwitchController* switchController = initSwitchController(); struct CursorController* ctrl = initCursorController(mouse->super, switchController, keyController); alt_up_char_buffer_string(char_buffer, "Loading Sounds ", 30, 30); audioController = initAudioController(); loadSound( audioController, LOOP_ONE ); loadSound( audioController, LASER_SOUND ); alt_irq_register(AUDIO_IRQ, audioController, (void*) audio_ISR); alt_irq_enable(AUDIO_IRQ); play_background_loop( audioController, LOOP_ONE ); enableAudioController( audioController ); printhex(info.score); mainMenu(mouse, ctrl, p); disableAudioController(audioController); stop_background_loop(audioController); unloadSoundById(audioController, LASER_SOUND); unloadSoundById(audioController, LOOP_ONE); alt_up_char_buffer_string(char_buffer, "Loading Sounds ", 30, 30); //loadSound(audioController, WIN_SOUND); //loadSound(audioController, LOSE_SOUND); loadSound( audioController, TOWER_UPGRADE_SOUND ); loadSound( audioController, LOOP_TWO ); play_background_loop(audioController, LOOP_TWO); enableAudioController( audioController ); alt_up_char_buffer_clear(char_buffer); //usleep(1000); struct Alien* testAlienCollection[60]; gameSetup(p, shipAnimationCollection, mouse, starAnimation, star2Animation); usleep(500000); //time delay for panel to be drawn // char LPS[50]; float lps_; int n = 0; for(n = 0; n < 20; n++) { testAlienCollection[n] =initAlien(n, 10*n, 10, alien0, explode1, "IdontKnow", 1.4, 150, 500, collisionChecker); addToEnvNR(p, testAlienCollection[n]->super); } for(n = 0; n < 20; n++) { testAlienCollection[n+20] =initAlien(10*n, n, 10, alien1, explode1, "whatName", 1.4, 190, 850, collisionChecker); addToEnvNR(p, testAlienCollection[n+20]->super); } for(n = 0; n < 20; n++) { testAlienCollection[n+40] =initAlien(10*n, n, 20, bossAnimate, explode1, "IamBoss", 1.6, 800, 1500, collisionChecker); testAlienCollection[n+40]->score = 300; addToEnvNR(p, testAlienCollection[n+40]->super); } int stage = 0; /* * Game Starts!!!!!! */ alt_alarm_start (&alarm,alt_ticks_per_second(),my_alarm_callback,(void*)p); int startTimer = 0; char second_row1[15]; alt_up_character_lcd_set_cursor_pos(char_lcd_dev, 0, 1); sprintf(second_row1, "wave# %d ", stage); alt_up_character_lcd_string(char_lcd_dev, second_row1); while(1) { alt_timestamp_start(); start_time = (unsigned)alt_timestamp(); /*-----------------------------------------------------------------------------------------------*/ checkCollision(collisionChecker); //a major function that check each collision happen between each object updateCursorController(ctrl, 1); count++; if (startTimer > count) info.startButton = false; else { if(stage == 7) info.isWin = true; else if(startTimer == count){ //play_background_loop(audioController, LOOP_TWO); enableAudioController( audioController ); } } if (info.startButton){ disableAudioController(audioController); //stop_background_loop(audioController); startTimer = count + 15000; checkStages(testAlienCollection, stage%7, collisionChecker); stage++; //if(stage > 6) stage = 0; info.startButton = false; alt_up_character_lcd_set_cursor_pos(char_lcd_dev, 0, 1); sprintf(second_row1, "wave# %d ", stage); alt_up_character_lcd_string(char_lcd_dev, second_row1); } if(info.isEnd || info.isWin) { disableAudioController(audioController); stop_background_loop(audioController); endGame(testAlienCollection, collisionChecker, p, mouse, ctrl, keyController); } /*-----------------------------------------------------------------------------------------------*/ end_time = (unsigned)alt_timestamp(); lps_ = (float)alt_timestamp_freq()/(float)(end_time - start_time); sprintf(LPS, "The current LPS is %.2f", lps_); alt_up_char_buffer_string(char_buffer, LPS, 3, 2); } return 0; }