void alt_irq_init ( const void* base ) { NIOS2_WRITE_IENABLE(0); alt_irq_cpu_enable_interrupts(); }
/*************************************************************************************** * Main program: exercises various features of the DE2 Media Computer, as a test * and to provide an example. * It performs the following: * 1. tests the SRAM repeatedly * 2. scrolls some text on the hex displays, which alternates between "dE2" and * "PASSEd" if there is no SRAM error detected, and "Error" if an error is detected * 3. flashes the green LEDs. The speed of flasing and scrolling for 2. is controlled * by timer interrupts * 4. connects the SW switches to red LEDs * 5. handles pushbutton interrupts: pushing KEY1 speeds up the scrolling of text, * pushing KEY2 slows it down, and pushing KEY3 stops the scrolling * 6. can test the JP1, JP2 expansion ports, if a ribbon cable is installed between them * 7. echos text received from the JTAG UART (such as text typed in the * terminal window of the Monitor Program) to the serial port UART, and vice versa ****************************************************************************************/ int main(void) { /* Declare volatile pointers to I/O registers (volatile means that IO load * and store instructions will be used to access these pointer locations, * instead of regular memory loads and stores) */ volatile int * interval_timer_ptr = (int *) INTERVAL_TIMER_BASE; volatile int * pushbutton_ptr = (int *) PUSHBUTTON_BASE; /* initialize 7-segment displays buffer (dE2 just before being visible on left side) */ display_buffer[0] = 0xdE2; display_buffer[1] = 0x0; display_buffer[2] = 0x0; green_LED_pattern = 0x55555555; // used for a flashing pattern on the green lights eight_sec = 0; // initialize 8-second delay counter display_toggle = 0; // display initialized to scroll the text dE2 shift_direction = 1; // initial shift direction is to the right *(interval_timer_ptr + 1) = 0x7; // Set START = 1, CONT = 1, ITO = 1 *(pushbutton_ptr + 2) = 0xE; // Set the 3 interrupt mask bits to 1 (bit 0 is Nios II reset) #if !RIBBON_CABLE_INSTALLED NIOS2_WRITE_IENABLE( 0x3 ); // Set interrupt mask for the interval timer and pushbuttons #else NIOS2_WRITE_IENABLE( 0x3 | 0x1000 ); // also enable expansion port (JP2) interrupts #endif NIOS2_WRITE_STATUS( 1 ); // Enable Nios II interrupts int * SRAM_ptr; int SRAM_write = 0x55555555; int SRAM_read; int memory_error = 0; while ( !memory_error ) { SRAM_ptr = (int *) SRAM_BASE; while( (SRAM_ptr < (int *) SRAM_END) & !memory_error ) { Update_HEX_display ( display_buffer[1] ); Update_red_LED ( ); // read slider switches and show on red LEDs Update_UARTs ( ); // update both the JTAG and serial port UARTs /* only test the Expansion ports if there is a 40-pin ribbon cable connected between them. */ #if RIBBON_CABLE_INSTALLED if (!Test_expansion_ports ( )) { memory_error = 1; // use this to break out of the while loop } #endif // test SRAM * SRAM_ptr = SRAM_write; SRAM_read = * SRAM_ptr; if (SRAM_read != SRAM_write) { memory_error = 1; } SRAM_ptr += 1; }; SRAM_write = ~SRAM_write; if ( eight_sec > 80 ) { eight_sec = 0; // restart the 8-second delay counter if ( display_toggle == 0 ) { display_toggle = 1; display_buffer[0] = 0xbA55Ed; // code for the word PASSEd display_buffer[1] = 0x0; display_buffer[2] = 0x0; } else { display_toggle = 0; display_buffer[0] = 0xdE2; // code for the word dE2 display_buffer[1] = 0x0; display_buffer[2] = 0x0; } } }; display_buffer[0] = 0xe7787; // code for the word Error display_buffer[1] = 0x0; display_buffer[2] = 0x0; while ( 1 ) { Update_HEX_display ( display_buffer[1] ); } return 0; }
/* * To initialize the internal interrupt controller, just clear the IENABLE * register so that all possible IRQs are disabled. */ void altera_nios2_qsys_irq_init(void) { NIOS2_WRITE_IENABLE(0); }