Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++

General Interrupt Problem

Altera_Forum
Honored Contributor II
1,092 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
369 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
0 Kudos
Altera_Forum
Honored Contributor II
369 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).
0 Kudos
Reply