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

Changes in power/power.h and device.h libraries from NCS v1.5.1 to NCS v1.6.1

Hi Dev Team,

I had installed the newest NCS version NCS v1.6.1 and was importing my application from 1.5.1 to 1.6.1.

However, I noticed a lot of changes with respect to the libraries.

The most significant one was the <power/power.h> which has changed to <pm/pm.h>

Also, I observed a difference in <device.h> library.

I had a piece of code written in 1.5.1:

//==============================================================================
/** @brief Turn uart on or off */
void uart_enable(bool doEnable) {
  uint8_t devState;
  if (doEnable) {
    devState = DEVICE_PM_ACTIVE_STATE;
  } else {
    devState = DEVICE_PM_OFF_STATE;
  }

  // Turn off logging (which is using UART0):
  const struct device* console =
      device_get_binding(DT_LABEL(DT_NODELABEL(uart0)));
  device_set_power_state(console, devState, NULL, NULL);

  // Turn off UART1:
  const struct device* uart1 =
      device_get_binding(DT_LABEL(DT_NODELABEL(uart1)));
  device_set_power_state(uart1, devState, NULL, NULL);
}

I changed it to the below code in 1.6.1 to make the code compile:

/** @brief Turn uart on or off */
void uart_enable(bool doEnable) {
  uint8_t devState;
  if (doEnable) {
  //  devState = DEVICE_PM_ACTIVE_STATE;
      devState = PM_STATE_ACTIVE;
  } else {
  //  devState = DEVICE_PM_OFF_STATE;
      devState = PM_STATE_SOFT_OFF;
  }

  // Turn off logging (which is using UART0):
  const struct device* console =
      device_get_binding(DT_LABEL(DT_NODELABEL(uart0)));
  //device_set_power_state(console, devState, NULL, NULL);
  //pm_power_state_set();
  pm_constraint_set(PM_STATE_ACTIVE);

  // Turn off UART1:
  const struct device* uart1 =
      device_get_binding(DT_LABEL(DT_NODELABEL(uart1)));
  //device_set_power_state(uart1, devState, NULL, NULL);
  pm_constraint_set(PM_STATE_SOFT_OFF);
}

I wanted to know if the new code I have written is equivalent to the one I had in the previous 1.5.1 version.

I had to ask this as it gets really confusing sometimes when moving from 1 NCS version to another.

Regards,

Adeel.

Related