Zephyr work queue and interrupt

Hello,

We are developing an application using nrf52832 and the ncs 1.8.0.

Since our solution is battery operated we have configures application to sleep by default and wake-up on the interrupt.

In our case, this interrupt is PWM like pulses. So, once we receive the interrupt we wake-up the system and then start processing the interrupt. Since this is PWM like pulses, we have train of interrupts. And our ISR processes this interrupt (basically calculating the pulse width of pwm).

Now, when interrupt is being processed in ISR we need to make some operations based on the pulse width calculated in the ISR. To start this processing, we want to start a thread when first interrupt arrives. So far we tried:
1. Starting a thread from the ISR on first interrupt. However, this fails since thread invocation is not allowed in the ISR.
2. Submit a system work queue from ISR, which in turn starts the thread. This works, but it seems kernel takes time to schedule this work queue (since ISR is always running). It takes extended time to start the thread (in seconds), which is obviously not accepted.
3. Start a timer from ISR and once it expired, start a thread from timer handler. However, this also fails since it's same as case-1. Starting the thread from ISR context.

In work around to this? Is there any example that does something similar?

TIA!

Parents
  • Hi Sigurd,

    Thanks. semaphore is what I was thinking to use for synchronization, however, it will still need my thread to be created at the start and then it will always be running in wait state. Since, most of the time we are in deep sleep, I was thinking to start the thread only when needed and then stop it completely (rather then waiting) when not needed.

    Does thread waiting for semaphore in deep sleep consume more power?

    TIA!

  • Hello!

    I assume that by deep sleep you are referring to System OFF mode?

    In that case no threads are running while in System OFF mode and on wakeup the system is reset, so waiting for a semaphore in deep sleep wouldn't make much sense.

    If you are referring to normal sleep/idle mode, then waiting for a semaphore would not consume more power than just idling, and would be the recommended way to wait for an interrupt in a power constrained system.

    Best regards,

    Einar

Reply
  • Hello!

    I assume that by deep sleep you are referring to System OFF mode?

    In that case no threads are running while in System OFF mode and on wakeup the system is reset, so waiting for a semaphore in deep sleep wouldn't make much sense.

    If you are referring to normal sleep/idle mode, then waiting for a semaphore would not consume more power than just idling, and would be the recommended way to wait for an interrupt in a power constrained system.

    Best regards,

    Einar

Children
No Data
Related