This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

NRF9160 Zephyr Idle Hooks

Hi,

Is it possible to be notified when the device is entering/exiting idle? All I can see is that idle thread calling k_cpu_idle which doesn't appear to have any hooks? I see you can enable CONFIG_SYS_POWER_DEEP_SLEEP_STATES, and CONFIG_HAS_SYS_POWER_STATE_DEEP_SLEEP_1 which does call functions when exiting and entering, but that calls nrf_regulators_system_off(NRF_REGULATORS) which is not ideal as the only wake up sources are then external.

Essentially I want to know the system is entering idle so I can power down any external devices that aren't needed, and power them back up when exiting idle.

The only thing I can think of doing is modifying the power.c file in zephyr\soc\arm\nordic_nrf\nrf91\power.c and adding a new power state to sys_set_power_state(), which just calls k_cpu_idle(). Is there a better way to do this? I'd prefer not to have to change that any library files...

Kind regards,

Thomas

Parents Reply Children
  • One solution could be to create a thread with the lowest priority that executes a loop and when it gets the CPU nothing else is scheduled and you can make your desired action. Then you can sleep in this thread for some time to make sure checks are not done too often.

    However, what do you mean by "external devices"? If you want to control the on-chip peripherals, they have power management hooks that are called when the device enters deep sleep.

    Best regards,

    Simon

  • Hi Simon,

    Yes, that’s the issue - the power management hooks are only used when entering deep sleep and deep sleep enters the system off mode which is undesirable. 

    Kind regards,

    Thomas

  • Would this solution work for you:

    "One solution could be to create a thread with the lowest priority that executes a loop and when it gets the CPU nothing else is scheduled and you can make your desired action. Then you can sleep in this thread for some time to make sure checks are not done too often."

    Or would you rather use some of the already present Zephyr/NCS libraries to achieve this? I have not looked too much into the Power Management library, but I can do some investigation or ask internally if you would like to.

    You could also ask you question here, since this is a Zephyr related question.

    Best regards,

    Simon

Related