4 Replies Latest reply on Apr 14, 2016 7:43 PM by kwagjj_1632506

    hybernation withint ISR not working

    kwagjj_1632506

      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?