Interrupt not getting triggered everytime in Zephyr project

Hello, 

I have a zephyr project built using NCS v1.8.0 with target board selected as nRF9160DK_nrf9160_ns. I am interfacing LSM6DSO sensor with nRF9160 dk, with interrupt configuration done using NRF GPIOTE. Issue with the project is sometimes the interrupt pin is getting triggered and  after some time it stops triggering or getting struck i have to reset the board. 

Can anyone please look at the below code and let me know why my interrupt pin is not triggering after sometime. I am using k_cpu_atomic_idle implementation because of the race condition might occur when i use simple implementation of k_cpu_idle.  

Please help.... 

Here is my sample code : 

Below is my configuration for Interrupt pin. I am using semaphore as mentioned in zephyr docs as i want to put my example in k_cpu_idle mode for power saving. 

static k_sem my_sem;
static volatile bool interrupt_flag = false;



static void lsm6dsox_interrupt_handler(nrfx_gpiote_pin_t pin, nrf_gpiote_polarity_t action)
{
  if(interrupt_flag == false)
  {
    printk("Interrupt genrated\r\n");

    interrupt_flag = true;
    k_sem_give(&my_sem); 
    
  }
  
  }
  
  
  
void gpio_init(void)
{
    nrfx_err_t err;

    /* Connect GPIOTE_0 IRQ to nrfx_gpiote_irq_handler */
    IRQ_CONNECT(DT_IRQN(DT_NODELABEL(gpiote)),
                DT_IRQ(DT_NODELABEL(gpiote), priority),
                nrfx_isr, nrfx_gpiote_irq_handler, 0);


    err = nrfx_gpiote_init(0);
    if (err != NRFX_SUCCESS) 
    {
      //printk("nrfx_gpiote_init error: %08x\r\n", err);
      return;
    }


  /* Initialize input pin to generate event on high to low transition (falling edge) */
    nrfx_gpiote_in_config_t in_config;
    in_config.sense = NRF_GPIOTE_POLARITY_LOTOHI;
    in_config.pull = NRF_GPIO_PIN_NOPULL;
    in_config.is_watcher = false;
    in_config.hi_accuracy = 1;
    in_config.skip_gpio_setup = false;

    err = nrfx_gpiote_in_init(INT_PIN, &in_config, lsm6dsox_interrupt_handler);
    if (err != NRFX_SUCCESS) {
            //printk("nrfx_gpiote_in_init error: %08x\r\n", err);
            return;
    }
  
    /* Enable the interrupt events */
    nrfx_gpiote_in_event_enable(INT_PIN, true);

}

 

Here is the while loop of my main function, where i am using semaphore for signalling between ISR and my while loop of main function . In while loop I have to perform some data processing whenever an sensor interrupt is generated. In the processing section I have used k_sleep function to provide delay to the processing tasks. And after all data processing is done I am reading the senor interrupt source register to clear the interrupt as my sensor is configured with interrupt latch enabled. After reading source register I am unlocking iqr and waiting for next interrupt. 

  while(1)
  {

    unsigned int key = irq_lock();
    
    /** Wait for semaphore from ISR  */
    if (k_sem_take(&my_sem,K_NO_WAIT) == 0)
    {
    
      if(interrupt_flag ==  true)
      {
        /* Doing some data processing here */        
        
        /* Read the sesnor interrupt source register in do while loop untill the interrupt flag is cleared */

        /* reset interrupt flag */
        interrupt_flag = false;
      }

      irq_unlock(key);

    }
    else
    {
      k_cpu_atomic_idle(key);
    }

  }

}

And here is my proj.conf file for the same example : 

CONFIG_GPIO=n
CONFIG_NRFX_GPIOTE=y
CONFIG_LOG_PROCESS_THREAD_SLEEP_MS=100

CONFIG_I2C=y
CONFIG_I2C_NRFX=y

CONFIG_SERIAL=y
CONFIG_TRUSTED_EXECUTION_NONSECURE=y
CONFIG_UART_INTERRUPT_DRIVEN=y
CONFIG_MAIN_STACK_SIZE=8192


#for flashing using mcu bootloader
CONFIG_BOOTLOADER_MCUBOOT=y 

Can anyone please tell where I am going wrong ? Or provide me with appropriate code snippet to help me out. 

Related