View previous topic :: View next topic |
Author |
Message |
Trampas Guest
|
Dynamic ISR functions |
Posted: Thu Aug 05, 2004 7:49 am |
|
|
OK I have an external interrupt, which depending on certain states the interrupt has different applications. So I was looking at coding up the ISR like:
void ISR()
{
if (state)
{
//do thist
}else
{
//do other thing
}
}
However the latency is problem for my application. Thus I was wondering if it was possible to write two ISR functions then swap out pointers to the functions depending on the state? Do this make sense?
Thanks
Trampas |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Thu Aug 05, 2004 8:21 am |
|
|
Are you saying that a simple if statement is causing too much latency? It probably only equates to a couple of asm instructions. |
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1934 Location: Norman, OK
|
One possible approach |
Posted: Thu Aug 05, 2004 8:29 am |
|
|
Not sure where your latency issues are but this approach might work for you.
I have an application where, while in the ISR, I test some inputs and flags to determine system state then set a global var to a specific non zero value (actually I OR the items together into the global) and exit.
In the main routine I do a test of the global value. If it is non-zero I use a SWITCH{} routine to check the variable and perform the specific function then set it to back 0 waiting for the next interrupt.
Last edited by dyeatman on Thu Aug 05, 2004 2:25 pm; edited 1 time in total |
|
|
Trampas Guest
|
|
Posted: Thu Aug 05, 2004 9:20 am |
|
|
Well my loop is kind of critical as I have to tell the difference in 10us and 20us timing. That is I have a wire coming in with one of two communication protocals on the wire. Thus I can enable one of the protocals and test, if that one is not supported I switch to the second one.
Thus it would be easier to have two ISR functions and then set one active, if that is not the correct protocal, remove that ISR and set the second active.
Since my timing of the protocal is on the order of a few microsecs every cycle counts, especially with the overhead of the ISR to begin with. Yes it most likely will work with the if statement, but it is not a clean, easy to understand, or as fast as just changing the goto address for the ISR.
Trampas |
|
|
Trampas Guest
|
|
Posted: Thu Aug 05, 2004 10:35 am |
|
|
I guess since the ISR goto address is in FLASH it would be a pain to do dynamic ISRs, oh well, live an learn...
Next board revision I will run the same wire/trace to two external interrupts then I can enable/disable the ISR I want.
Trampas |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Thu Aug 05, 2004 11:29 am |
|
|
CCS does allow pointers to functions so you could actually call a function from you ISR. This function is pointed to by the pointer. It might look cleaner but could take more instructions to execute.
If you wrote you own ISR handlers and use priority interrupts, you could switch that interrupt from high to low and have two different routines. |
|
|
bdavis
Joined: 31 May 2004 Posts: 86 Location: Colorado Springs, CO
|
|
Posted: Sat Sep 04, 2004 8:48 am |
|
|
Mark -
It states in a FAQ or something that CCS does not allow pointers to functions. You have a lot of posts, so I assume you did get this working - could you show me how? I'm currently using a switch statement to call different functions, and would like to use pointers to functions. Thanks |
|
|
treitmey
Joined: 23 Jan 2004 Posts: 1094 Location: Appleton,WI USA
|
|
Posted: Tue Sep 07, 2004 7:58 am |
|
|
Is this the referance your talking about. It is in the help file, under FAQ.
Code: | enum tasks {taskA, taskB, taskC};
run_task(tasks task_to_run) {
switch(task_to_run) {
case taskA : taskA_main(); break;
case taskB : taskB_main(); break;
case taskC : taskC_main(); break;
}
} |
|
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
|
|