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

Returning from interrupt to a specified address in main

I'm quite new to context switch and embedded software development. I'm developing a standalone application (no OS) with aduc7026 and keil uVision3. My problem is that at the end of an uart messagge, which I must receive by interrupt, depending on the content of the messagge I've to return return in main in the state saved before entering in the ISR or I've have to return in a specified point where a funcion call is executed.

Hoping that I've been clear. Does anyone have suggestions?

Thank ìs in advance,

Matteo

Parents
  • Your supervisor is either a skilled developer, or (s)he isn't.

    If skilled, then I'm convinced you have misunderstood something. If not, then it's time you suggest he/she switches from supervisor to developer and implements the failure.

    The closest you can expect to get directing further evaluation from an interrupt is with a RTOS. An interrupt can tell the scheduler that it should perform a rescheduling. Such a rescheduling will mean that the program doesn't return to the same place it was before the interrupt. But it does not jump to a fixed address. Instead it jump to the current location of that other thread.

    So if you do get a rescheduling to a thread that was already busy with a long command, that command will have to be computed to the end (unless you have state machines within the threads). The scheduler will only switch to that thread if it had the highest priority. But if it had, then you wouldn't even need any rescheduling because then the thread was already busy with the previous command when the interrupt came.

    In the end, you either have commands that are fully processed before the processor reschedules. Or you have one or more state machines, where you can force a restart of a state machine.

    Note that restarting a state machine from an ISR can't be done by just assigning a new value to the state variable. The reason is that the ISR may be activated while the state machine is busy handling state x, and the state machine may after the ISR process a source line that assigns a new state, overwriting the expected new state from the ISR. So having a ISR forcing a new state should be done by setting a separate variable "force_state", and the state machine should check this variable to see if it should switch state at the top or bottom of the state machine loop. In some situations, you may even need cleanup states.

    Any attempts to have an ISR force a fixed return address will end with a black eye and a bloody nose. A C compiler expects that a single thread is always executed sequentially without anything interfering. And ISR or OS scheduler must be written to be invincible. They may "pause time" for a task, but execution must return at the exact same place with all registers and relevant variables in their known states. If not, then your program will not fulfill the requirements of the C standard, and all bets are off what will really happen. You would then have introduced a number of random dices giving you percentages on an infinite number of potential failures in your code.

    In reality, you will get the same if the main program is written in assembler. The reason is that no normal human developer can write code while assembler instruction by assembler instruction all the time think about the concept of the execution breaking at an arbitrary position just to jump to another position.

    State machines have the advantage that they only switch action between two states. So the states can be documented. And it's possible to keep track of what happens when breaking between two states since the behaviour of the program will follow the C rules.

Reply
  • Your supervisor is either a skilled developer, or (s)he isn't.

    If skilled, then I'm convinced you have misunderstood something. If not, then it's time you suggest he/she switches from supervisor to developer and implements the failure.

    The closest you can expect to get directing further evaluation from an interrupt is with a RTOS. An interrupt can tell the scheduler that it should perform a rescheduling. Such a rescheduling will mean that the program doesn't return to the same place it was before the interrupt. But it does not jump to a fixed address. Instead it jump to the current location of that other thread.

    So if you do get a rescheduling to a thread that was already busy with a long command, that command will have to be computed to the end (unless you have state machines within the threads). The scheduler will only switch to that thread if it had the highest priority. But if it had, then you wouldn't even need any rescheduling because then the thread was already busy with the previous command when the interrupt came.

    In the end, you either have commands that are fully processed before the processor reschedules. Or you have one or more state machines, where you can force a restart of a state machine.

    Note that restarting a state machine from an ISR can't be done by just assigning a new value to the state variable. The reason is that the ISR may be activated while the state machine is busy handling state x, and the state machine may after the ISR process a source line that assigns a new state, overwriting the expected new state from the ISR. So having a ISR forcing a new state should be done by setting a separate variable "force_state", and the state machine should check this variable to see if it should switch state at the top or bottom of the state machine loop. In some situations, you may even need cleanup states.

    Any attempts to have an ISR force a fixed return address will end with a black eye and a bloody nose. A C compiler expects that a single thread is always executed sequentially without anything interfering. And ISR or OS scheduler must be written to be invincible. They may "pause time" for a task, but execution must return at the exact same place with all registers and relevant variables in their known states. If not, then your program will not fulfill the requirements of the C standard, and all bets are off what will really happen. You would then have introduced a number of random dices giving you percentages on an infinite number of potential failures in your code.

    In reality, you will get the same if the main program is written in assembler. The reason is that no normal human developer can write code while assembler instruction by assembler instruction all the time think about the concept of the execution breaking at an arbitrary position just to jump to another position.

    State machines have the advantage that they only switch action between two states. So the states can be documented. And it's possible to keep track of what happens when breaking between two states since the behaviour of the program will follow the C rules.

Children
No data