120 likes | 223 Views
ECT 358. Lecture 25 Interrupts. The best way to forget your own problems is to help someone solve his. Look not every man on his own things, but every man also on the things of others. Phillippians 2:4. Interrupts. MicroBlaze has one interrupt port.
E N D
ECT 358 Lecture 25 Interrupts
The best way to forget your own problems is to help someone solve his. Look not every man on his own things, but every man also on the things of others. Phillippians 2:4
Interrupts • MicroBlaze has one interrupt port. • An interrupt controller peripheral is required for handling more than one interrupt signal.
Interrupt Sources • Interrupt Controller Peripheral • Peripheral with an Interrupt Port • External Interrupt Port • Interrupt Handlers • Interrupt Vector Table in MicroBlaze • Interrupt Routines in MicroBlaze
Interrupt Action • Interrupt occurs • MicroBlaze jumps to address location 0x10 • Interrupt Vector Table contains address of Interrupt Handler for Interrupt Source • MicroBlaze jumps to address of Interrupt Handler (Subroutine) • Subroutine returns and MicroBlaze returns to original code execution
Interrupt Controller Peripheral • An interrupt controller peripheral should be used for handling multiple interrupts. • The interrupt handler for the interrupt controller peripheral is automatically generated by Libgen. • Peripherals are handled by individual interrupt handlers in the order of their priority. • The interrupt controller handler services each interrupt signal that is active starting from the highest priority signal. • Each of the peripheral interrupt signals needs to be associated with an ISR.
Peripheral with Interrupt • Change the following lines of the MHS snippet in the OPBTIMER section to the following port Interrupt = interrupt port CaptureTrig0 = net_gnd Delete references to other interrupt controller
Peripheral with Interrupt • Change the following lines of the MSS snippet in the OPBTIMER section to the following parameter INT_HANDLER = timer_int_handler, INT_PORT = Interrupt timer_int_handler is the name of your interrupt service routine. Delete references to other interrupt controller.
Interrupt Handlers You can write your own interrupt handlers, or ISRs, for any peripherals that raise interrupts. You write these routines in C as with other functions. You can give the interrupt handler function any name with the signature void func (void *). Alternately, you can elect to register the handlers defined as a part of the drivers of the interrupt sources.
Example C File #include <xtmrctr_l.h> void timer_int_handler(void * baseaddr_p) { int status; status = XTmrCtr_mGetControlStatusReg(baseaddr_p, 0); if (status & XTC_CSR_INT_OCCURED_MASK) { /* your code here */ /* Clear the timer interrupt */ XTmrCtr_mSetControlStatusReg(baseaddr_p, 0, status); } }
Example C File void main() { /* initializations */ microblaze_enable_interrupts(); XTmrCtr_mSetLoadReg(XPAR_OPB_TIMER_1_BASEADDR, 0, 1000000); /* reset the timers, and clear interrupts */ XTmrCtr_mSetControlStatusReg(XPAR_OPB_TIMER_1_BASEADDR, 0, XTC_CSR_INT_OCCURED_MASK | XTC_CSR_LOAD_MASK ); /* start the timers */ XTmrCtr_mSetControlStatusReg(XPAR_OPB_TIMER_1_BASEADDR, 0, XTC_CSR_ENABLE_TMR_MASK | XTC_CSR_ENABLE_INT_MASK | XTC_CSR_AUTO_RELOAD_MASK | XTC_CSR_DOWN_COUNT_MASK); /* Wait for interrupts to occur */ while (1); }