IRQCode

Table of contents
No headers
How the IRQ Code Works for the Nios II Processor

Introduction
Altera’s Nios® II Processor Reference Handbook and the Nios II Software Developer’s Handbook discuss the details of interrupt service routine (ISR) and interrupt request (IRQ) handling.However, they do not relate this to the actual code written.So the intent of this document is to relate these documents to the “real” code and give a few insights.Most IRQ problems have to do with spurious interrupts, or interrupts which get asserted but then go away before the processor has a serviced them. 
IMPORTANT NOTE:Interrupts for Nios II are Level sensitive. 
What happens when an IRQ is asserted? 
Like most RISC-based processors, the Nios II processor has only one “real” interrupt.However, it is capable of accepting 32.Each of the 32 is “ANDED” with the corresponding bit of the ienable register.The result of that is fed into the ipending register so it can be read by the processor. Then the “OR” of all the ipending is then ANDED with the PIE bit.This resulting signal becomes the hardware interrupt.So for the interrupt to be recognized, the corresponding ienable bit must be set in the ienable register, and the PIE bit must also be enabled.See Figure 3-1 in the Nios II Processor Reference Handbook
On initialization
Upon reset, the status register is set to zero.Because the PIE bit is a bit in the status register, it too is cleared, disabling all hardware interrupts (except reset which is nonmaskable). After reset, the code immediately jumps to _reset (defined in the SOPC Builder). This code (in components/nios2/altera_nios2/HAL/src/crt0.S) then initializes the instruction cache and then jumps to _start (in components/nios2/altera_nios2/HAL/src/crt0.S). This code then initializes the data cache, copies the code sections that need to moved, zeros out the bss space, sets up the stack address and then jumps to alt_main (in components/nios2/altera_hal/HAL/src/alt_main.c).Here alt_irq_init is called (c:\\\\altera\\\\kits\\\\nios2_60\\\\components\\\\altera_nios2\\\\HAL\\\\inc\\\\sys\\\\alt_irq.h). Alt_irq_init does two things. It zeros out the ienable registers and turns on the PIE bit in the status register.
Then the rest of the Hardware Abstraction Layer (HAL) is initialized by calling alt_syst_init and then main is called. 

What happens when you register an interrupt?
To register an interrupt, you call the function alt_irq_register (irq#, context, handler) (c:\\\\altera\\\\kits\\\\nios2_60\\\\components\\\\altera_hal\\\\HAL\\\\src\\\\alt_irq_register.c).This function does the following:
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 code disables interrupts (PIE bit set low), then it adds the handler and contexts to the arrays meant to keep that info.Then, if the handler is not NULL, it enables the corresponding bit in the ienable status register. Otherwise, it disables it, turning the interrupt handling off.Then it re-enables interrupts by turning the PIE back on.
Now that an interrupt is pending, what happens?
If an IRQ is asserted and the corresponding ienable register bit is enabled, the interrupt will be passed to the processor.The processor will finish executing the two instructions left in the pipe. Then the processor will start the exception processing. In hardware, the processor will push most of the registers and the return address to the stack (see Exception Processing in the Nios II Processor Reference Handbook), and then jump to the exception location (set in the SOPC Builder).
The first code that it will execute is the alt_exception_entry code (c:\\\\altera\\\\kits\\\\nios2_60\\\\components\\\\altera_nios2\\\\HAL\\\\src\\\\alt_exception_entry.S)
This code will do some stack checking if that was a compile option.Then it will save off the working registers so the ISR doesn’t have to worry about which registers can be used.Additionally if it is determined not to be a hardware interrupt, the code will reread the instruction that caused the exception to determine what type of exception needs to be processes.
Not all of the code is in alt_execption_entry.S.It is scattered among several files.The only way to see how they really fit together is to look at the linker file.Here is how the linker puts things together:
PROVIDE (__ram_exceptions_start = ABSOLUTE(.));
. = ALIGN(0x20);
*(.irq)
<a href= "www.emark.co.cc/a>
KEEP (*(.exceptions.entry.user));
KEEP (*(.exceptions.entry));
KEEP (*(.exceptions.irqtest.user));
KEEP (*(.exceptions.irqtest));
KEEP (*(.exceptions.irqhandler.user));
KEEP (*(.exceptions.irqhandler));
KEEP (*(.exceptions.irqreturn.user));
KEEP (*(.exceptions.irqreturn));
KEEP (*(.exceptions.notirq.label));
KEEP (*(.exceptions.notirq.user));
KEEP (*(.exceptions.notirq));
KEEP (*(.exceptions.soft.user));
KEEP (*(.exceptions.soft));
KEEP (*(.exceptions.unknown.user));
KEEP (*(.exceptions.unknown));
KEEP (*(.exceptions.exit.label));
KEEP (*(.exceptions.exit.user));
KEEP (*(.exceptions.exit));
KEEP (*(.exceptions));
It starts off with the exceptions.entrysection, which is the code from the first part of the alt_execption_entry.S file that stores all of the registers. Once the processor finishes the .entry code, it drops into the next section. 
Then next section exceptions.irqtest has the code for testing what caused the exception. This code is found in c:\\\\altera\\\\kits\\\\nios2_60\\\\components\\\\altera_nios2\\\\HAL\\\\src\\\\alt_irq_entry.S.It tests the PIE bit and the ipending register.If either are zero, it jumps to .Lnot_irq.
Otherwise, the code falls to the next section. Here the alt_irq_handler is called (c:\\\\altera\\\\kits\\\\nios2_60\\\\components\\\\altera_hal\\\\HAL\\\\src\\\\alt_irq_handler.c).When the IRQ code finishes, it returns to sectionexceptions.irqreturnwhich causes the code to go to exception_exit (in alt_execption_entry.S).This restores all the registers and returns to the user code. 
If the exception is not a hardware IRQ, the code goes to section exceptions.notirq then to exceptions.softwhere traps and unimplemented instructions are filtered out ( alt_exception_trap.S and alt_software_exception.S).
Finally, if no source has been identified, the code falls into section exceptions.unknown. Here a break will be triggered if the debug core is installed.Otherwise, it will sit in an infinite loop (alt_exception_entry.S).If you want it to ignore the interrupt, you can simply comment out the break or br 0b and the code will continue to the exit.You may also want to set a hardware register or flag to indicate this has happened.
The most common reason for getting to this point is a spurious interrupt, where the IRQ went away before the ISR was called.SignalTap may be your best way to capture spurious interrupts. 
Conclusion
Understanding what is going on in the ISR code can help you debug your system.The code is fairly straightforward once you see how it is put together. 
Tag page
Viewing 15 of 39 comments: view all
Heartbeats Headphones | Cheap Watches sale you with Rolex watches, Breitling Watches and so on.Rolex watches are one of the hottest selling Cheap Watches.rolex datejusts|cartier steel watches|omega watches sale
Posted 06:52, 6 Apr 2010
the north facethe north facenorth face jacketnorth face jacketnorth face jacketsnorth face jacketsnorth facenorth facenorth face outletnorth face outletnorth pole clothingnorth pole clothingnorth face bootsnorth face bootsnorth face salenorth face salenorth pole jacketnorth pole jacketThe North Face clothingThe North Face clothingnorth face jackets on salenorth face jackets on salehe north face backpacksthe north face backpacksnorth face arctic jacketnorth face arctic jacketNorth Face Mens JacketsNorth Face Mens Jackets pandora pandorapandora bracelets pandora braceletspandora charms pandora charmspandora jewellery pandora jewellerypandora beads pandora beadspandora uk pandora ukpandora necklace pandora necklacepandora jewelry pandora jewelryPandora BanglePandora Banglepandora charms braceletspandora charms braceletscharm bracelets pandoracharm bracelets pandoraandora bracelets ukpandora bracelets uk links bracelet links bracelet links london bracelet links london bracelet friendship bracelet friendship bracelet links friendship bracelet links friendship bracelet sweetie bracelet charms sweetie bracelet charms links london charms links london charms links charms links charms charm bracelets charm bracelets links bracelet sweetie links bracelet sweetie charm links bracelet charm links bracelet sweetie bracelet sweetie bracelet links charms sale links charms saleLinks Necklace Links NecklaceLinks Bangle Links BangleLinks Earrings Links EarringsLinks Rings Links Ringsinks Chains Links Chainslinks of london links of london links london links london links of london jewellery links of london jewellery links of london sale links of london sale links london sale links london sale ugg boots ugg bootsAs Seen On TV As Seen On TVVideo Game AccessoriesVideo Game Accessories Laptop Batteries Laptop Batteriesed hardy clothing ed hardy clothing Abercrombie And Fitch Abercrombie And Fitch tiffany jewellery tiffany jewellery
Posted 01:19, 7 Apr 2010
While strapless mother of the bride dresses dresses will always be a popular style of wedding dress, 2010 brings about more options for Evening gowns covering up. Formal shrugs and bolero jackets are available from many ugg boots wedding dress designers in 2010, along with options for adding straps for the reception. Pick-up style wedding dresses have been making their way out of Bridal gowns wedding fashion for the last few years, but 2010 Wedding gowns signals an end to that wedding trend. While some discount wedding Cocktail Dresses lines may feature a dress Flower Girl Dresses or two uggs bootswith the pick-up style Evening Dresses skirt, they won’t dominate the wedding fashion scene like they did in Columbia Sportswear the past. Colors other than white will continue to play a part in 2010 wedding trends. Some wedding dresses Bridal Dress will feature small Bridesmaid Dresses splashes of color, such as a contrasting sash. Other popular wedding dress Wedding Dresses colors will be champagne, deep ivory, and antique Wedding Dress lace wigs gold.
Posted 06:16, 8 Apr 2010
kamagra tablets kamagra jelly Buy kamagra
Posted 07:56, 10 Apr 2010
hello
Posted 11:19, 11 Apr 2010
Good edited 11:19, 11 Apr 2010
Posted 11:19, 11 Apr 2010
hello
Posted 11:19, 11 Apr 2010
hello
Posted 11:19, 11 Apr 2010
hello
Posted 11:19, 11 Apr 2010
sheepskin boots sheepskin boots sheepskin ugg boots sheepskin ugg boots ugg boots ugg boots uggs uggs ugg australia ugg australia ugg sale ugg sale ugg boots sale ugg boots sale cheap ugg boots cheap ugg boots winter boots winter boots discount ugg boots discount ugg boots cheap uggs cheap uggs uggs on sale uggs on sale australia ugg boots australia ugg boots ugg boots 2010 ugg boots 2010 ugg boots womens ugg boots womens womens uggs womens uggs womens ugg boots womens ugg boots bailey button ugg boots bailey button ugg boots classic tall ugg boots classic tall ugg boots classic short ugg boots classic short ugg boots classic cardy ugg boots classic cardy ugg boots classic mini ugg boots classic mini ugg boots metallic ugg boots metallic ugg boots nightfall ugg boots nightfall ugg boots sundance ii ugg boots sundance ii ugg boots ultra tall ugg boots ultra tall ugg boots ultra short ugg boots ultra short ugg boots Abercrombie And Fitch Abercrombie And Fitch Abercrombie Abercrombie Abercrombie Clothing Abercrombie Clothing Abercrombie UK Abercrombie UK Abercrombie London Abercrombie London Abercrombie Fitch Abercrombie Fitch Abercrombie Outlet Abercrombie Outlet Abercrombie Jeans Abercrombie Jeans Abercrombie Pants Abercrombie Pants Abercrombie Tees Abercrombie Tees Abercrombie Shorts Abercrombie Shorts Abercrombie Sweater Abercrombie Sweater Abercrombie Outerwear Abercrombie Outerwear Abercrombie Hoodies Abercrombie Hoodies Abercrombie Polo Abercrombie Polo Abercrombie ShirtsAbercrombie Shirts abercrombie henleys crew abercrombie henleys crew hollister hollister hollister uk hollister uk abercrombie mens abercrombie mens abercrombie womens abercrombie womens Ruehl 925 Ruehl 925 MBT MBT MBT Shoes MBT Shoes MBT sale MBT sale MBT UK MBT UK MBT Fitness Shoes MBT Fitness Shoes MBT Sale Shoes MBT Sale Shoes MBT Outlet MBT Outlet MBT Lami shoes MBT Lami shoes MBT M.Walk shoes MBT M.Walk shoes MBT Sport Shoes MBT Sport Shoes ed hardy clothing ed hardy clothing Abercrombie Clothing Abercrombie Clothing Cartier Jewelry Cartier Jewelry GHD GHD G Star Raw G Star Raw Abercrombie And Fitch Abercrombie And Fitch ugg boots ugg boots tiffany jewellery tiffany jewellery Gucci Gucci
Posted 06:48, 12 Apr 2010
Abercrombie & Fitch (NYSE: ANF), abercrombie henleys crew Abercrombie Hoodies the pricey teen clothing retailer, said today it will continue to markdown Abercrombie London its clothes in order to boost sales.ugg boots Jonathan Ramsden, CFO for Abercrombie, said the company will give up Abercrombie Clothing margins to improve its sales. In February Abercrombie Outerwear Abercrombie said same-store sales were abercrombie mens hollister uk up Abercrombie Fitch Abercrombie Shorts Abercrombie Tees 5% year-over-year, but average abercrombie womens unit prices were down 14% due to discounting. Abercrombie initially refused to markdown its clothing at the start of the recession in 2008 and lost market lace wigs to rivals American Eagle Outfitters hollister Ruehl 925 (NYSE: AEO) Abercrombie and Aeropostale (NYSE: ARO). Sales declined dramatically for Abercrombie during wedding dresses Abercrombie Shirts the recession Abercrombie Outlet and the company posted nine consecutive quarters Abercrombie UK of same-store Abercrombie Pants sale declines. Mr. Ramsden said the company hopes to report same-store sales increases for Abercrombie Polo 2010. While Abercrombie And Fitch impressive, given that every month in 2010 Abercrombie Sweater will be compared against double-digit drops in Abercrombie Jeans sales is not too difficult to achieve. ugg boots
Posted 07:21, 12 Apr 2010
The city of Oakland experienced a 2.73% decrease in median sales price from last year going down from $338,497 (Dec. 08) to $329,260 (Dec. 09). A $9,000 decrease in median sales price is hardly significant, thus we need to take a closer look at some additional statistics in order to determine how Oakland ca homes for sale fared over the course of a year. Median days on market data for Oakland shows that houses are selling faster than Dec 08. It took 50 days in Dec 08 for a house to sell and for Dec 09 that number has gone down to 34 days (a 31.43% improvement). We cannot be so brash as to attribute the change to a $9,000 drop in median sales price, so for now let’s take a look at unit sales and see where that takes us. In the month of Dec 08, 302 units were sold compared to 295 for Dec 09 – 2.32% change which is hardly noteworthy. In the end, it is important to note that Oakland’s housing market has not shown much change from Dec 08 – 09 except in median days on market category.This does reflect buyers eagerness to pick up whatever inventory comes on the market. Unlike Oakland neighbors Dublin and Danville both suffered a significant drop in median sales price. Dublin ca homes for sale featured a 10.42% drop and Danville ca homes for sale saw a 15.60% drop. Like Oakland, both cities saw a drop in median days on market at 44.68% for Dublin and 34.95% for Danville. In the units sold category Dublin sold 1 more unit in Dec 09 than 08 however Danville was the real winner here showing a massive 294.12% increase in units sold (17 in Dec 08 to 67 in Dec 09). HEMET Ca Foreclosures | Home For Sale | 3.5% FHA | Home For Sale | LANCASTER Ca Foreclosures | 100% VA | MOUNTAIN VIEW Ca Foreclosures | NEWPORT BEACH Ca Foreclosures | Zero Down USDA | PLEASANTON Ca Foreclosures | ROSEVILLE Ca Foreclosures | Half Percent Down | SALINAS Ca Foreclosures | SAN BERNARDINO Ca Foreclosures | 203 K FHA | SAN CLEMENTE Ca Foreclosures | SAN MATEO Ca Foreclosures | Conventional Loans | Alameda Ca Foreclosures | APPLE VALLEY Ca Foreclosures | Jumbo Loans | BRENTWOOD Ca Foreclosures | CONCORD Ca Foreclosures | City Down Payment | CUPERTINO Ca Foreclosures | DALY CITY Ca Foreclosures | 2yr BK Discharge OK | FULLERTON Ca Foreclosures | Mortgage Calculator | <620 FICO with No 12 mo lates | Mortgage Calculator | HAYWARD Ca Foreclosures | 620+ FICO Ok | HESPERIA Ca Foreclosures | Laguna Beach Ca Foreclosures | 6% Seller Credit OK | LOS GATOS Ca Foreclosures | MERCED Ca Foreclosures | 30 Yr Fixed | NAPA Ca Foreclosures | PALM DESERT Ca Foreclosures | 15 Yr Fixed | PERRIS Ca Foreclosures | REDWOOD CITY Ca Foreclosures | 20 Yr Fixed | SANTA CLARA Ca Foreclosures | SANTA CRUZ Ca Foreclosures | 5 Yr Adjustable | VALLEJO Ca Foreclosures | WHITTIER Ca Foreclosures | 7 Yr Adjustable | CASTRO VALLEY Ca Foreclosures | COSTA MESA Ca Foreclosures | 10 Yr Adjustable
Posted 22:19, 12 Apr 2010
Viewing 15 of 39 comments: view all
You must login to post a comment.
SourceForge.net