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 support@ccsinfo.com

Managing interrupts
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
kgng97ccs



Joined: 02 Apr 2022
Posts: 97

View user's profile Send private message

PostPosted: Thu Jul 21, 2022 9:11 pm     Reply with quote

Thank you, Ttelmah.

Actually I have encountered warnings on both READBITA and WRITEBITA.

1. Would it be safe to ignore these warnings if the words READBITA and WRITEBITA do not appear in the .lst file?

2. What exactly are the WRITEBITA and READBITA functions? I don't seem to be able to find more information about them anywhere.
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Fri Jul 22, 2022 3:52 am     Reply with quote

The code I posted generates a writebita function. Generally it is the internal
name for a read or write function on portA, involving access using a
variable.
Look in the symbol list to find 'where' it is, and then the lst file for
this address will show the function.
kgng97ccs



Joined: 02 Apr 2022
Posts: 97

View user's profile Send private message

PostPosted: Tue Dec 27, 2022 8:41 pm     Reply with quote

I have a program part that goes like this:
Code:
...

void function4()
{
   ...
   ...
}

void function3()
{
   ...
   ...
}

void function2()
{
   ...
   if (...) function3();
   if (...) function4();
   ...
}

void function1()
{
   ...
   function2();
   ...
}

#int_timer0
void timer0_timeout_isr()
{
   ...
   /* Take action here */
   ...
}

main()
{   
   ...
   ...
   
   while (true)
   {
      /* Step 1 */
      if (condition==1) function1();
      
      /* Step 2 */
      if ...
      
      /* Step 3 */
      if ...
   }
}

Here, function1 calls function2, and function2 calls function3 and function4.

The timer0 timeout interrupt can occur anywhere in function1, function2, function3, or function4.

I understand that if the interrupt occurs, the timeout ISR will be serviced, and the program will return to the point where the interrupt was called.

However, I would like the program to get out of all the functions altogether immediately after the timeout ISR is serviced; that is, the program will get out of function1 and proceed to Step 2 immediately after the ISR is serviced.

Is that possible, and if yes, what do I need to do?

I will appreciate any ideas. Thank you.
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Wed Dec 28, 2022 2:23 am     Reply with quote

The normal way would be to just add a global 'flag' variable, perhaps
called something like 'leave', and have this default to FALSE, but when the
interrupt occurs set it to 'TRUE', then in each of the functions have the
code regularly have code like:
Code:

   if (leave)
       return;


Then back in the main set leave back to FALSE.
kgng97ccs



Joined: 02 Apr 2022
Posts: 97

View user's profile Send private message

PostPosted: Sat Dec 31, 2022 5:27 am     Reply with quote

Thank you, Ttelmah.

Let’s say I have a global flag that is set to 1 in the timeout ISR:
Code:
#int_timer0
void timer0_timeout_isr()
{
   /* Take action here */
   ...

   leave = 1;
}

I am not sure if this thinking is correct:
The timeout interrupt can happen at any point within any of the functions (1, 2, 3, or 4). If I would like the program to get out of all the functions once the ISR has completed its job, then theoretically I need to have the “if (leave) return;” line before and after each and every statement in each function so that the program will get out of all the functions one after another once the ISR is done -- and without processing any more code . As it may not be practical to put so many “if (leave) return;” lines, I could just put this line right before and right after every function call and allow the called function to process some code if the timeout interrupt occurs within the called function.

Example:
Code:
void function4()
{
   ...

   /* Timeout occurs here */
   /* The remaining code will still be processed before function4 returns */

   ...
}

void function3()
{
   ...
   ...
}

void function2()
{
   ...

   if (leave)return;
   if (...) function3();
   if (leave)return;
   if (...) function4();
   if (leave)return;

   ...
}

void function1()
{
   ...

   if (leave)return;
   function2();
   if (leave)return;

   ...
}

I will appreciate any comments. Thank you.
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Sat Dec 31, 2022 5:54 am     Reply with quote

You need to think out your operations and code structures.
Understand that if your code jumped out from halfway through actually
completing something, you could end up with values from this halfway
through point. You need to organise what is done in the functions, so that
you test for 'leave' at every point where the values would be complete.
You don't want to leave an inner function with things 'half done'.
Get rid of the idea of getting out of the functions immediately. Instead
you want to be leaving 'as soon as possible', with the emphasis on the
'possible'.
kgng97ccs



Joined: 02 Apr 2022
Posts: 97

View user's profile Send private message

PostPosted: Sun Jan 15, 2023 2:53 am     Reply with quote

Thank you, Ttelmah, for your comments, which have helped me appreciate the problems I will face.

I have now abandoned the idea of getting out of all the functions immediately one after another.

Reason:
Since the timeout can occur anywhere in any of the functions, it will be difficult to know what can or will be completed (and some things could be half-done, as you said), and what the states of the various variables are at the time the timeout occurs. It could be that the program is stuck at a particular statement, such that it will not go pass that statement no matter how long I wait. So however I get out of the functions, there may be things that are not done or not properly done, and without a clear idea of what things are done and what things are not done, it will be difficult to continue the program after I got out of all the functions. So, I decided to simply do a reset of the MCU when the timeout occurs. For my program, this timeout, if it occurs, will prompt me to debug the program to see what is causing the timeout – I will come to that when it occurs.

Thanks again.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 
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