PWMOut: lock deesleep addition

As PWMOut in most cases depend on high speed freq clock, it should lock deepsleep while active.
pull/5177/head
Martin Kojtal 2017-09-22 14:59:07 +01:00
parent c6f655c02e
commit 5a6aee43eb
1 changed files with 26 additions and 1 deletions

View File

@ -21,6 +21,7 @@
#if defined (DEVICE_PWMOUT) || defined(DOXYGEN_ONLY) #if defined (DEVICE_PWMOUT) || defined(DOXYGEN_ONLY)
#include "hal/pwmout_api.h" #include "hal/pwmout_api.h"
#include "platform/mbed_critical.h" #include "platform/mbed_critical.h"
#include "platform/mbed_sleep.h"
namespace mbed { namespace mbed {
/** \addtogroup drivers */ /** \addtogroup drivers */
@ -56,12 +57,18 @@ public:
* *
* @param pin PwmOut pin to connect to * @param pin PwmOut pin to connect to
*/ */
PwmOut(PinName pin) { PwmOut(PinName pin) : _deep_sleep_locked(false) {
core_util_critical_section_enter(); core_util_critical_section_enter();
pwmout_init(&_pwm, pin); pwmout_init(&_pwm, pin);
core_util_critical_section_exit(); core_util_critical_section_exit();
} }
~PwmOut() {
core_util_critical_section_enter();
unlock_deep_sleep();
core_util_critical_section_exit();
}
/** Set the ouput duty-cycle, specified as a percentage (float) /** Set the ouput duty-cycle, specified as a percentage (float)
* *
* @param value A floating-point value representing the output duty-cycle, * @param value A floating-point value representing the output duty-cycle,
@ -71,6 +78,7 @@ public:
*/ */
void write(float value) { void write(float value) {
core_util_critical_section_enter(); core_util_critical_section_enter();
lock_deep_sleep();
pwmout_write(&_pwm, value); pwmout_write(&_pwm, value);
core_util_critical_section_exit(); core_util_critical_section_exit();
} }
@ -177,7 +185,24 @@ public:
} }
protected: protected:
/** Lock deep sleep only if it is not yet locked */
void lock_deep_sleep() {
if (_deep_sleep_locked == false) {
sleep_manager_lock_deep_sleep();
_deep_sleep_locked = true;
}
}
/** Unlock deep sleep in case it is locked */
void unlock_deep_sleep() {
if (_deep_sleep_locked == true) {
sleep_manager_unlock_deep_sleep();
_deep_sleep_locked = false;
}
}
pwmout_t _pwm; pwmout_t _pwm;
bool _deep_sleep_locked;
}; };
} // namespace mbed } // namespace mbed