09b_Interrupts_In_CPP

09b_Interrupts_In_CPP - ECE 2534 Writing Interrupt Code...

Info iconThis preview shows pages 1–6. Sign up to view the full content.

View Full Document Right Arrow Icon
ECE 2534 riting Interrupt Code Writing Interrupt Code (Almost) ntirely in C++ Entirely in C++
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
• The following is an example to illustrate the “mechanics” of using interrupts on the MicroBlaze • The program turns all LEDs ON, and then blinks one of them with a 1-second period • A few details are left for you to implement
Background image of page 2
timers.h interrupts.h ain() halfsecond.cpp timers.cpp interrupts.cpp main() { . . . } . . . microblaze_enable_interrupts.s
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
///////////////////////////////////////////////////////// // PROGRAM: halfsecond.cpp DESCRIPTION: se timer module ( th terrupts) to blink LED0 every 500 ms Main Program (p. 1 of 2) // DESCRIPTION: Use timer module (wth interrupts) to blink LED0 every 500 ms // #include "interrupts.h" #include "timers.h" // Global variables to be used by the interrupt handler, masterISR() static volatile int *Leds = (int *) 0x75290000; static volatile int Led_state; int main(void) { // Initialize LEDs Led_state = 0xff; *Leds = Led_state; // Initialize interrupts rmInterrupts INTR TIMER MASK ); armInterrupts( INTR_TIMER_MASK ); // Initialize the timer so that it will generate an interrupt every 500 ms Timer0_init_interrupts( TIMER_HALF_SEC ); // Start the timer Timer0_start(); while(1) { // Main loop -- Could do useful things here } t rn 0 return 0; }
Background image of page 4
/////////////////////////////////////////////////////// Main Program (p. 2 of 2) ///////////////////////////////////////////////////////// // masterISR: This is the Interrupt Service Routine. // It is not to be "called" as a normal subroutine. // If interrupts have been enabled, then masterISR is activated when an interrupt occurs. // A prototype of this function must be declared with the attribute "interrupt_handler". // void masterISR(void) { const unsigned int isr = *INTC_ISR; // Read the Intr Status Register // Verify that the interrupt was caused by the timer (isr & INTR TIMER MASK) if (isr & INTR_TIMER_MASK) { // THE FOLLOWING ORDER OF EVENTS IS IMPORTANT // Re-arm the timer by writing 1 to TCSR[TINT] *TIMER0_TCSR = *TIMER0_TCSR; // Acknowledge to the INTC that the interrupt is being serviced gp g *INTC_IAR = INTR_TIMER_MASK; // Toggle LED0
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 02/07/2011 for the course ECE 2534 taught by Professor Abbott during the Fall '10 term at Virginia Tech.

Page1 / 12

09b_Interrupts_In_CPP - ECE 2534 Writing Interrupt Code...

This preview shows document pages 1 - 6. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online