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

Jumping to function after timer interrupt

In my program, I have a periodic timer interrupt written in C.

What I need to achieve is to have the interrupt service routine jump to another function after the interrupt service routine is executed.

However, the catch is that the address of the function (which the program is suppose to jump) is stored as a variable (which is not fixed each time the interrupt occurs).

Im looking for advice on how can this possibly be done. Thank you.

Parents
  • If you were to explain why you are trying to do this it might be easier to help.

    So far it looks as though you don't ever want execution to return to the 'main' program after this interrupt handler has been executed, you want your endless loop function to run, however you want all ISRs to continue executing in response to interrupts.

    This sounds quite strange - perhaps you could design your program differently?

    Stefan

Reply
  • If you were to explain why you are trying to do this it might be easier to help.

    So far it looks as though you don't ever want execution to return to the 'main' program after this interrupt handler has been executed, you want your endless loop function to run, however you want all ISRs to continue executing in response to interrupts.

    This sounds quite strange - perhaps you could design your program differently?

    Stefan

Children
  • Yes you are right. The program would not return to 'main'. Instead it will jump from function to function.

    The purpose of doing this is to create an application which can run different tasks (functions) in a round robin fashion. These tasks can execute forever until they are pre-empted by another task when the timer interrupt sets in.

    What I describe may sound a bit pointless but it is actually part of an overall effort to build a context switching routine for a very basic real-time OS in 8051.

  • The purpose of doing this is to create an application which can run different tasks (functions) in a round robin fashion. These tasks can execute forever until they are pre-empted by another task when the timer interrupt sets in.

    To make a preemptive multi-tasker on an 8051, I don't think you'll get by with writing everything in C. You'll have to code at least some of the core pieces in assembly. You'll have to manipulate the stack on each context switch triggered by the timer interrupt.

    I would strongly suggest to re-evaluate that plan. Preemptive multitasking is hard to do on an 8051, and harder still if you want to stick with C as the implementation language. Cooperative multitasking may very well be a better choice.