esp_pm: fix an issue and add an interface Closes IDF-2984 and IDF-2944 See merge request espressif/esp-idf!12787