hybernation withint ISR not working

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

I'm currently trying to make a simple switch to act as a button that will go to hybernation when it is pressed longer than 3 seconds.

   

Since I am using a timer ISR that will be called every second, I just thought calling 'CySySPmHibernate()' inside the ISR(timer_intr_handler) would work. (code shown below)

   

 

   
    

CY_ISR(timer_isr_handler){
    isr_timer_ClearPending();
    Timer_1_ReadStatusRegister();

    if( sec_count++ >=3){
        

    

       
        CySysPmHibernate();
       
    }
}

   
   

 

   

 

   

I'm guessing the problem is that the reason why this doesn't work is that the hybernation has been initiated while inside an ISR.

   

So I did eventually bypass this problem by simply using a global variable acting as a flag that will be check in the main loop.

   

 

   
    

int hybernation_flag=0 // global variable

    

...

    

CY_ISR(timer_isr_handler){
    isr_timer_ClearPending();
    Timer_1_ReadStatusRegister();
    if( sec_count++ >=3){
         hybernation_flag=1;
    }
}

    

int main(void){

    

...

    

for(;;){

    

    if(hybernation_flag==1){
        CySysPmHibernate();
    }
}
}

   
   

 

   

So my question is :

   

Q1. Am I right to think that malfunction in hybernation when it is triggered while inside an ISR is a bad practice?

   

Q2. If so, why is it a bad practice?

   

Q3. Is there a way to trigger hybernation properly even inside an ISR?

0 Likes
4 Replies
lock attach
Attachments are accessible only for community members.
rola_264706
Level 8
Level 8
50 likes received 25 likes received 10 likes received

Here is the App for this.

0 Likes
Anonymous
Not applicable

thank you I'll have to take some time to read the whole thing

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Q2. If so, why is it a bad practice? Well, an interrupt handler disturbs the normal program flow. Hence, usual practice is to keep handlers short. Really short, Just clearing the interrupt source, setting a flag and go back into the shadows. In the main-loop the flag is checked and acted on accordingly.

   

 

   

Bob

0 Likes
Anonymous
Not applicable

thank you. I guess your reply does make sense and it probably is one reason why i shouldn't do hybernation within an interrupt.

   

But still, i wonder if there is a more technical, architectural reason why one is to be forbidden of such practice....

0 Likes