This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Modify the return from interrupt

Hello !

I have an interrupt like this :
void int_timer_0 (void) interrupt 1
{
... instructions ...
if ( condition ) {
// power down
}
... instructions ...
}

In the interrupt, i want to execute an C function 'power_down' (this function power down the product with an infinite loop ). But the interrupt (timer 0) must be call on the next timer overflows because it is used to transmit the power down information.
So, i want to put in the stack the address of the function to call and make a return from interrupt. I want to insert a code like this :
#pragma asm
push ??? ; power_down address (high)
push ??? ; power_down address (low)

reti
#pragma endasm
but i don't know the syntax for the address of 'C' fucntion.

Thanks

Benoit.

Parents
  • I know that my solution to make a speudo return from interrurpt is not easy, but when i detect a power down, i must power down the system. I think that i will not have memory problem because the power down will stop the execution. I kown that the stack will be corrupted but the data in the stack will not be use again.
    I can not use a flag and let the main process to do the power down, because the main porcess can be in some action that take 1 minites and i must power down as soon as possible.

    Benoit.

Reply
  • I know that my solution to make a speudo return from interrurpt is not easy, but when i detect a power down, i must power down the system. I think that i will not have memory problem because the power down will stop the execution. I kown that the stack will be corrupted but the data in the stack will not be use again.
    I can not use a flag and let the main process to do the power down, because the main porcess can be in some action that take 1 minites and i must power down as soon as possible.

    Benoit.

Children
  • In the interrupt, i want to execute an C function 'power_down' (this function power down the product with an infinite loop ).
    Do you mean "power_down" or "reset"
    I can not use a flag and let the main process to do the power down, because the main porcess can be in some action that take 1 minites and i must power down as soon as possible.
    Why not just do an infinite loop in the ISR and let the watchdog do the reset?

    Erik

  • I mean open the alimentation line (so the microcontroleur will lost its power). On my board, the power down is done by sending 8 bits on a serial line. The timing of this line is done by the interrrupt in which i detect the need to power down.

  • Ok, but why not just a reset?

    I fail to see why you would want to power down. Let us know.

    Erik

  • In the interrrupt, i detect that the power must be stopped (in fact i detect that the 'on/off' button had been activated). So the microcontroleur must send a message to the board of the system that control the power. And this board will disconnect the batterie and the whole system will be powered off.(power off is the good expression, power down is not).

    A reset will just restart the microcontroleur, it is not what i want.

  • if the interrupt(s) required to execute the power off function are of a higher priority than the interrupt you are in, you can call power off from inside the interrupt you are in.
    If power off is called from the main as well you will need two copies or a NOAREG.

    Erik