CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Dynamic ISR functions

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Trampas
Guest







Dynamic ISR functions
PostPosted: Thu Aug 05, 2004 7:49 am     Reply with quote

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

View user's profile Send private message Send e-mail

PostPosted: Thu Aug 05, 2004 8:21 am     Reply with quote

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

View user's profile Send private message

One possible approach
PostPosted: Thu Aug 05, 2004 8:29 am     Reply with quote

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







PostPosted: Thu Aug 05, 2004 9:20 am     Reply with quote

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







PostPosted: Thu Aug 05, 2004 10:35 am     Reply with quote

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

View user's profile Send private message Send e-mail

PostPosted: Thu Aug 05, 2004 11:29 am     Reply with quote

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

View user's profile Send private message

PostPosted: Sat Sep 04, 2004 8:48 am     Reply with quote

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 Very Happy
treitmey



Joined: 23 Jan 2004
Posts: 1094
Location: Appleton,WI USA

View user's profile Send private message Visit poster's website

PostPosted: Tue Sep 07, 2004 7:58 am     Reply with quote

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

View user's profile Send private message Send e-mail

PostPosted: Tue Sep 07, 2004 8:00 am     Reply with quote

See this post and see if it makes sense to you

http://www.ccsinfo.com/forum/viewtopic.php?t=20416
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group