]> git.earman.xyz Git - sensor-watch.git/commitdiff
make the HAL sleep function obey the chip documentation
authorAlex Maestas <git@se30.xyz>
Mon, 18 Dec 2023 03:06:10 +0000 (03:06 +0000)
committerAlex Maestas <git@se30.xyz>
Mon, 18 Dec 2023 03:09:36 +0000 (03:09 +0000)
the sleep mode doesn't get set immediately, and needs to be waited upon.

watch-library/hardware/hal/include/hpl_sleep.h
watch-library/hardware/hal/src/hal_sleep.c
watch-library/hardware/hpl/pm/hpl_pm.c

index 6731ec30e4077da57919b8715c2f5f554132126e..4106fb7305eacde8c25fe20f5ceab4bc88afd3fc 100644 (file)
@@ -70,6 +70,16 @@ extern "C" {
  */
 int32_t _set_sleep_mode(const uint8_t mode);
 
+/**
+ * \brief Get the sleep mode for the device
+ *
+ * This function gets the sleep mode for the device.
+ *
+ * \return the current value of the sleep mode configuration bits
+ */
+int32_t _get_sleep_mode(void);
+
+
 /**
  * \brief Reset MCU
  */
index 89472f156acd17459b88ad5b5402c700d7d9ce16..fd9c84cbe055e31123c7124920659fe677473275 100644 (file)
@@ -57,6 +57,9 @@ int sleep(const uint8_t mode)
        if (ERR_NONE != _set_sleep_mode(mode))
                return ERR_INVALID_ARG;
 
+        // wait for the mode set to actually take, per chip doc.
+        while(_get_sleep_mode() != mode);
+
        _go_to_sleep();
 
        return ERR_NONE;
index d6439f1d24c46cacc81d6fe028efd5a06caa0f59..2e9e37b5fe055001f7e137fc638cbcf653569c13 100644 (file)
@@ -63,6 +63,14 @@ int32_t _set_sleep_mode(const uint8_t mode)
        return ERR_NONE;
 }
 
+/**
+ * \brief Get the sleep mode for the device
+ */
+int32_t _get_sleep_mode()
+{
+    return hri_pm_read_SLEEPCFG_SLEEPMODE_bf(PM);
+}
+
 /**
  * \brief Set performance level
  */