cancel
Showing results for 
Search instead for 
Did you mean: 

PSoC 4 MCU

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
Reply
4 Replies
Honored Contributor II

Here is the App for this.

0 Likes
Reply
Anonymous
Not applicable

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

0 Likes
Reply
Esteemed Contributor II

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
Reply
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
Reply