diff options
author | Alex Maestas <git@se30.xyz> | 2023-12-18 03:06:10 +0000 |
---|---|---|
committer | Alex Maestas <git@se30.xyz> | 2023-12-18 03:09:36 +0000 |
commit | d96d6f9c919816a01a9139adf02a1063289cac27 (patch) | |
tree | 8833693fb9216e9f994ebb9fbd49ea92ab2451e2 /watch-library/hardware | |
parent | d10fa223b2fb85bbd79918ef6d19d16acb8e7af5 (diff) | |
download | Sensor-Watch-d96d6f9c919816a01a9139adf02a1063289cac27.tar.gz Sensor-Watch-d96d6f9c919816a01a9139adf02a1063289cac27.tar.bz2 Sensor-Watch-d96d6f9c919816a01a9139adf02a1063289cac27.zip |
make the HAL sleep function obey the chip documentation
the sleep mode doesn't get set immediately, and needs to be waited upon.
Diffstat (limited to 'watch-library/hardware')
-rw-r--r-- | watch-library/hardware/hal/include/hpl_sleep.h | 10 | ||||
-rw-r--r-- | watch-library/hardware/hal/src/hal_sleep.c | 3 | ||||
-rw-r--r-- | watch-library/hardware/hpl/pm/hpl_pm.c | 8 |
3 files changed, 21 insertions, 0 deletions
diff --git a/watch-library/hardware/hal/include/hpl_sleep.h b/watch-library/hardware/hal/include/hpl_sleep.h index 6731ec30..4106fb73 100644 --- a/watch-library/hardware/hal/include/hpl_sleep.h +++ b/watch-library/hardware/hal/include/hpl_sleep.h @@ -71,6 +71,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 */ void _reset_mcu(void); diff --git a/watch-library/hardware/hal/src/hal_sleep.c b/watch-library/hardware/hal/src/hal_sleep.c index 89472f15..fd9c84cb 100644 --- a/watch-library/hardware/hal/src/hal_sleep.c +++ b/watch-library/hardware/hal/src/hal_sleep.c @@ -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; diff --git a/watch-library/hardware/hpl/pm/hpl_pm.c b/watch-library/hardware/hpl/pm/hpl_pm.c index d6439f1d..2e9e37b5 100644 --- a/watch-library/hardware/hpl/pm/hpl_pm.c +++ b/watch-library/hardware/hpl/pm/hpl_pm.c @@ -64,6 +64,14 @@ int32_t _set_sleep_mode(const uint8_t mode) } /** + * \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 */ void _set_performance_level(const uint8_t level) |