Fpga Interrupt
Fpga Interrupt
Polling
An engineering example...
Waiting for an Event: Family Vacation
Polling Interrupts
Wake me up when we get there...
An engineering example...
Waiting for an Event: Button Push
Polling Interrupts
while(1) // Port 1 interrupt service routine
{ #pragma vector=PORT1_VECTOR
if(P1IFG & BIT2) // P1.2 IFG set __interrupt void Port_1(void)
{ {
P1IFG &= ˜BIT2; // P1.2 IFG cleared P1OUT ˆ= BIT0; // Toggle LED at P1.0
P1OUT ˆ= BIT0; // Toggle LED at P1.0 P1IFG &= ˜BIT2; // P1.2 IFG cleared
} }
TIMER_A 1 CPU
… 0
NMI 0
#pragma vector=WDT_VECTOR
Using Interrupt Keyword interrupt myISR(void){
Compiler handles context save/restore • Save context of system
Call a function? Then full context is saved • (optional) Re-enable interrupts
No arguments, no return values • *If group INT, read assoc IV Reg
(determines source & clears IFG)
You cannot call any TI-RTOS scheduler
functions (e.g. Swi_post) • Run your interrupt’s code
Nesting interrupts is MANUAL • Restore context of system
• Continue where it left off (RETI)
}
Interrupt Priorities (F5529)
INT Source Priority
System Reset high There are 23 interrupts
(partially shown here)
System NMI
User NMI
If multiple interrupts (of the 23) are
pending, the highest priority is
Comparator responded to first
Timer B (CCIFG0) 0xFFFF
By default, interrupts are not
Timer B nested …
WDT Interval Timer That is, unless you re-enable INT’s
Serial Port (A) during your ISR, other interrupts will be
held off until it completes
Serial Port (B)
It doesn’t matter if the new INT is a
A/D Convertor higher priority
As already recommended, you should
GPIO (Port 1) keep your ISR’s short
GPIO (Port 2) Most of these represent ‘groups’ of
Real-Time Clock low interrupt source flags
145 IFG’s map into these 23 interrupts
Interrupt Vector (IV) Registers
Returns highest
pending Port 1 IFG Port 1 Interrupt Vector Register (P1IV)
IV = Interrupt Vector register
Most MSP430 interrupts can be caused by more than one
source; for example:
Each 8-bi GPIO port one has a single CPU interrupt
IV registers provide an easy way to determine which
source(s) actually interrupted the CPU
The interrupt vector register reflects only ‘triggered’
interrupt flags whose interrupt enable bits are also set
Reading the ‘IV’ register:
Clears the pending interrupt flag with the highest priority
Provides an address offset associated with the highest priority
pending interrupt source
Memory Map
Interrupt Vectors & Priorities (F5529)
INT Source IV Register Vector Address Loc’n Priority
System Reset SYSRSTIV RESET_VECTOR 63 high
System NMI SYSSNIV SYSNMI_VECTOR 62 Flash (128K)
User NMI SYSUNIV UNMI_VECTOR 61
Comparator CBIV COMP_B_VECTOR 60
Timer B (CCIFG0) CCIFG0 TIMER0_B0_VECTOR 59 0xFFFF
Timer B TB0IV TIMER0_B1_VECTOR 58 INT Vectors (80)
WDT Interval Timer WDTIFG WDT_VECTOR 57
Serial Port (A) UCA0IV USCI_A0_VECTOR 56 RAM (8K)
Serial Port (B) UCB0IV USCI_B0_VECTOR 55
USB RAM (2K)
A/D Convertor ADC12IV ADC12_VECTOR 54
Info Memory (512)
GPIO (Port 1) P1IV PORT1_VECTOR 47 Boot Loader (2K)
Legend: Non-maskable Group’d IFG bits Let's look at the ISR for
Maskable Dedicated IFG bits the WDT (dedicated) interrupt...
Interrupt Service Routine (Dedicated INT)
INT Source IV Register Vector Address Loc’n
WDT Interval Timer WDTIFG WDT_VECTOR 57
GPIO_toggleOutputOnPin( ... );
}
Interrupt Service Routine (Dedicated INT)
INT Source IV Register Vector Address Loc’n
WDT Interval Timer WDTIFG WDT_VECTOR 57
Do not call interrupt handling functions directly (Rather, write to IFG bit)
Interrupts can be handled directly with C/C++ functions using the interrupt
keyword or pragma