I'm using Keil compiler for 8051Warp uP. I would like to make a jump from an interrupt routine back to the main function, this way: main () { init_function(); if (setjmp(env)!=0) { // Recovery procedure here ... } while (1) { // body of my program ... } } void irq (void) interrupt (12) { if (condition) longjmp (env,1); } void init_function() { IE = 0xA0; IEN1 = 0xC4; IP = 0x00; IP1= 0x40; } I'm experiencing the following problem. Right after the longjmp instruction, the execution actually restarts at the setjmp instruction point (as i wish), but no more interrupt can be serviced after this jump. It looks like the IE.7 bit has been reset in some way. Anyway, even if i set the IE / IE1 registers after the jump, no more interrupt are serviced by the uP. Somebody could help me? Thanx.
Pietro, I see gentlemen are discussing something rather different from your initial question. But to solve your problem you can use the following function just after your long jump: void dummy(void) { #pragma asm reti #pragma endasm } This function effectively does nothing but it resets interrupt service routine flag (not available directly) and thus reanables your interrupt. Be careful - if you have multiple interrupts EACH of them should be treated in this way. On the other hand, nothing bad will happen if you perform this function excessive number of times, so if you have enough time, you can do it in a loop. Regards, M.
Pietro, I see gentlemen are discussing something rather different from your initial question. I respectfully disagree. I think we all agree that longjmp() does not restore the MCU fully when invoked from an ISR. We are merely discussing two ways to do the same thing. longjmp() ignores the "priority level active" flip-flops and PSW (register banking!) entirely, but does handle restoring the MCU SP and reentrant SP's (whether you are using reentrancy or not). You are recommending handling the flip-flops after the longjmp(). To be truly safe, the PSW still needs attention in case a called function or ISR changed register banks. The "custom" longjmp() handles the flip-flops as a natural consequence of ISR return, but the stacked PSW can be modified to normalize bank selection upon return. If used, the reentrant SP can be handled before or after the return. The MCU's SP gets handled after the return. Do you now see how the two methods' results are not so different after all and how they both address the original issue? A comparison of complexity and maintainability, on the other hand, is an entirely different matter. I suppose my posts are driven by what I personally use the Discussion Forum for -- not so much for support, but to see other ways to do things that I might not have otherwise thought of and to get ideas. For example, detecting the slight odor of RTOS context switching in the "custom" longjmp() solution might get a reader thinking about simple context switching mechanisms to use in their next fun project. Oh well, sorry for the intrusion.