1

In my code, control is jumping from an interrupt service routine to some X function. After executing that X function, it's doing reset because it doesn't know to where it should return. Can you please tell me the what registers I need to take care of when jumping from interrupt service routine to function X ?

Scenario:

Function m() {
    Function x();
}

Function x() {
    Step1:
    Step2:call Function Y();
    Step3: 
}

Function y() {
    Step1:Enable interrupt;
    Step2:call function z();
    step3:disable interrupt;
}

interrupt() {
    Step1:Jump Step 3 of function x();
}

Explanation: Function Z should execute within some time duration so I'm using a timer interrupt to achieve that timeout. I'm giving step 3 of function x() address in interrupt service routine so that control will come back after particular time duration (jumping is achieved by changing the PC address).

Hardware: NEC V850E2 processor, GHS compiler. Software: Embedded C.

Devi
  • 171
  • 1
  • 1
  • 5
  • 2
    Are you saying that you're using your ISR to "kill" execution of Z(), and restore control to X()? This is tricky; in general, you need to unwind the stack. Alternatively, you may want to investigate setjmp and longjmp. – Oliver Charlesworth Nov 11 '11 at 12:40
  • yeah your understanding is correct..little bit tricky but i have to do that one... – Devi Nov 11 '11 at 12:59

1 Answers1

2

If GHS compilers are very compatible with GCC (as they claim), they might have the GCC __builtin_return_address (but this is not standard, and specific to GCC).

Maybe your target system is supported by a recent GCC? If yes, it could be worth to build GCC from source code.

Otherwise you need to write your own assembly code.

Basile Starynkevitch
  • 223,805
  • 18
  • 296
  • 547
  • Sorry..GHS and GCC both are completely different compilers...i cant use that function... – Devi Nov 11 '11 at 12:58