[STM32F0xx] Sleep API factorization

In order to enable sleep API factorization, HAL_Suspend/ResumeTick
functions have been implemented in hal_tick.c for each platform.
pull/2192/head
Erwan GOURIOU 2016-07-13 16:03:09 +02:00
parent 5cd73170ba
commit c1e0663922
7 changed files with 91 additions and 32 deletions

View File

@ -143,6 +143,21 @@ HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority) {
return HAL_OK;
}
void HAL_SuspendTick(void)
{
TimMasterHandle.Instance = TIM_MST;
// Disable HAL tick and us_ticker update interrupts (used for 32 bit counter)
__HAL_TIM_DISABLE_IT(&TimMasterHandle, (TIM_IT_CC2 | TIM_IT_UPDATE));
}
void HAL_ResumeTick(void)
{
TimMasterHandle.Instance = TIM_MST;
// Enable HAL tick and us_ticker update interrupts (used for 32 bit counter)
__HAL_TIM_ENABLE_IT(&TimMasterHandle, (TIM_IT_CC2 | TIM_IT_UPDATE));
}
/**
* @}
*/

View File

@ -108,6 +108,21 @@ HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority) {
return HAL_OK;
}
void HAL_SuspendTick(void)
{
TimMasterHandle.Instance = TIM_MST;
// Disable HAL tick
__HAL_TIM_DISABLE_IT(&TimMasterHandle, TIM_IT_CC2);
}
void HAL_ResumeTick(void)
{
TimMasterHandle.Instance = TIM_MST;
// Enable HAL tick
__HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC2);
}
/**
* @}
*/

View File

@ -108,6 +108,21 @@ HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority) {
return HAL_OK;
}
void HAL_SuspendTick(void)
{
TimMasterHandle.Instance = TIM_MST;
// Disable HAL tick
__HAL_TIM_DISABLE_IT(&TimMasterHandle, TIM_IT_CC2);
}
void HAL_ResumeTick(void)
{
TimMasterHandle.Instance = TIM_MST;
// Enable HAL tick
__HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC2);
}
/**
* @}
*/

View File

@ -155,6 +155,21 @@ HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority) {
return HAL_OK;
}
void HAL_SuspendTick(void)
{
TimMasterHandle.Instance = TIM_MST;
// Disable HAL tick and us_ticker update interrupts (used for 32 bit counter)
__HAL_TIM_DISABLE_IT(&TimMasterHandle, (TIM_IT_CC2 | TIM_IT_UPDATE));
}
void HAL_ResumeTick(void)
{
TimMasterHandle.Instance = TIM_MST;
// Enable HAL tick and us_ticker update interrupts (used for 32 bit counter)
__HAL_TIM_ENABLE_IT(&TimMasterHandle, (TIM_IT_CC2 | TIM_IT_UPDATE));
}
/**
* @}
*/

View File

@ -109,6 +109,21 @@ HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority) {
return HAL_OK;
}
void HAL_SuspendTick(void)
{
TimMasterHandle.Instance = TIM_MST;
// Disable HAL tick
__HAL_TIM_DISABLE_IT(&TimMasterHandle, TIM_IT_CC2);
}
void HAL_ResumeTick(void)
{
TimMasterHandle.Instance = TIM_MST;
// Enable HAL tick
__HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC2);
}
/**
* @}
*/

View File

@ -109,6 +109,21 @@ HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority) {
return HAL_OK;
}
void HAL_SuspendTick(void)
{
TimMasterHandle.Instance = TIM_MST;
// Disable HAL tick
__HAL_TIM_DISABLE_IT(&TimMasterHandle, TIM_IT_CC2);
}
void HAL_ResumeTick(void)
{
TimMasterHandle.Instance = TIM_MST;
// Enable HAL tick
__HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC2);
}
/**
* @}
*/

View File

@ -29,27 +29,12 @@
*/
#include "sleep_api.h"
#if DEVICE_SLEEP
#include "cmsis.h"
#if defined(TARGET_STM32F070RB)
void sleep(void) {
TIM_HandleTypeDef TimMasterHandle;
TimMasterHandle.Instance = TIM1;
// Disable HAL tick and us_ticker update interrupts
__HAL_TIM_DISABLE_IT(&TimMasterHandle, (TIM_IT_CC2 | TIM_IT_UPDATE));
// Request to enter SLEEP mode
HAL_PWR_EnterSLEEPMode(PWR_MAINREGULATOR_ON, PWR_SLEEPENTRY_WFI);
// Enable HAL tick and us_ticker update interrupts
__HAL_TIM_ENABLE_IT(&TimMasterHandle, (TIM_IT_CC2 | TIM_IT_UPDATE));
}
#elif defined(TARGET_STM32F030R8) || defined (TARGET_STM32F051R8)
void sleep(void) {
// Stop HAL systick
HAL_SuspendTick();
@ -59,22 +44,6 @@ void sleep(void) {
HAL_ResumeTick();
}
#else
static TIM_HandleTypeDef TimMasterHandle;
void sleep(void) {
TimMasterHandle.Instance = TIM2;
// Disable HAL tick interrupt
__HAL_TIM_DISABLE_IT(&TimMasterHandle, TIM_IT_CC2);
// Request to enter SLEEP mode
HAL_PWR_EnterSLEEPMode(PWR_MAINREGULATOR_ON, PWR_SLEEPENTRY_WFI);
// Enable HAL tick interrupt
__HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC2);
}
#endif
#if defined(TARGET_STM32F030R8) || defined (TARGET_STM32F051R8)
void deepsleep(void) {