Nios® II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++
Announcements
Intel Support hours are Monday-Fridays, 8am-5pm PST, except Holidays. Thanks to our community members who provide support during our down time or before we get to your questions. We appreciate you!

Need Forum Guidance? Click here
Search our FPGA Knowledge Articles here.

General Interrupt Problem

Altera_Forum
Honored Contributor II
789 Views

Hi everyone 

 

In my nios ii software in the main function there is "Function A" and "Function B" and there is a "Function C" which execute when interrupt occur like bellow 

 

--- Quote Start ---  

 

int main() 

//Function A 

//Function B 

 

//Function C 

 

--- Quote End ---  

 

while "Function A" is executing, interrupt occur and "Function C" start executing and after finishing executing the "Function C" is this possible to make the program to leave the "Function A" in what ever line of "function A" which was executing before occurring the interrupt and continue executing "Function B"? 

 

Please give me some suggestion 

Thank you so much
0 Kudos
2 Replies
Altera_Forum
Honored Contributor II
66 Views

You may try with the exception handler: you include functionA in a try/catch statement and let functionC throwing the exception. 

However I've never used the Nios exception handler, so I don't know if this actually works. 

 

Regards
Altera_Forum
Honored Contributor II
66 Views

You can't throw a C++ exception from a hardware interrupt. The context is all wrong. 

If you are running any kind of OS, you are constrained by what the OS allows interrupt routines to actually do. 

For Linux the interrupt routine can (at least indirectly) raise a signal on the process, when the process is next scheduled the relevant signal handler will run, and you are allowed to use longjump() to exit the signal hander - so can effectively exit A(). 

 

If you don't have an OS, and don't allow any nested interrupts, and you know exactly what the interrupt stack frame looks like, you might manage to use some global variables to control when the ISR modifies its return address. This is only really likely to work if A() is assembler. I did use this trick to get a sub 1MHz 6809 reading double-density floppies (not enough clock cycles between data bytes to actually count the sector length). 

 

If is probably safest to get the ISR to write to a memory location and check in A() for the value changing (make sure you use volatile).
Reply