This commit is contained in:
2025-03-19 11:06:57 +08:00
commit 49f5db3a10
1343 changed files with 599230 additions and 0 deletions

View File

@ -0,0 +1,6 @@
This software component is provided to you as part of a software package and
applicable license terms are in the Package_license file. If you received this
software component outside of a package or without applicable license terms,
the terms of the BSD-3-Clause license shall apply.
You may obtain a copy of the BSD-3-Clause at:
https://opensource.org/licenses/BSD-3-Clause

View File

@ -0,0 +1,258 @@
/**
******************************************************************************
* @file stm32_lpm.c
* @author MCD Application Team
* @brief Low Power Manager
******************************************************************************
* @attention
*
* <h2><center>&copy; Copyright (c) 2019 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include "stm32_lpm.h"
#include "utilities_conf.h"
/** @addtogroup TINY_LPM
* @{
*/
/* Private typedef -----------------------------------------------------------*/
/* Private macros ------------------------------------------------------------*/
/** @defgroup TINY_LPM_Private_macros TINY LPM private macros
* @{
*/
/**
* @brief macro used to initialized the critical section
*/
#ifndef UTIL_LPM_INIT_CRITICAL_SECTION
#define UTIL_LPM_INIT_CRITICAL_SECTION( )
#endif
/**
* @brief macro used to enter the critical section
*/
#ifndef UTIL_LPM_ENTER_CRITICAL_SECTION
#define UTIL_LPM_ENTER_CRITICAL_SECTION( ) UTILS_ENTER_CRITICAL_SECTION( )
#endif
/**
* @brief macro used to exit the critical section
*/
#ifndef UTIL_LPM_EXIT_CRITICAL_SECTION
#define UTIL_LPM_EXIT_CRITICAL_SECTION( ) UTILS_EXIT_CRITICAL_SECTION( )
#endif
/**
* @brief macro used to enter the critical section when Entering Low Power
* @note this macro is only called inside the function UTIL_LPM_EnterLowPower
* and in a basic configuration shall be identcal to the macro
* UTIL_LPM_EXIT_CRITICAL_SECTION. In general, the request to enter the
* low power mode is already done under a critical section and
* nesting it is useless (in specific implementations not even possible).
* So the users could define their own macro)
*/
#ifndef UTIL_LPM_ENTER_CRITICAL_SECTION_ELP
#define UTIL_LPM_ENTER_CRITICAL_SECTION_ELP( ) UTIL_LPM_ENTER_CRITICAL_SECTION( )
#endif
/**
* @brief macro used to exit the critical section when exting Low Power
* @note the behavior of the macro shall be symmetrical with the macro
* UTIL_LPM_ENTER_CRITICAL_SECTION_ELP
*/
#ifndef UTIL_LPM_EXIT_CRITICAL_SECTION_ELP
#define UTIL_LPM_EXIT_CRITICAL_SECTION_ELP( ) UTIL_LPM_EXIT_CRITICAL_SECTION( )
#endif
/**
* @}
*/
/* Private function prototypes -----------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private typedef -----------------------------------------------------------*/
/* Private defines -----------------------------------------------------------*/
/** @defgroup TINY_LPM_Private_define TINY LPM private defines
* @{
*/
/**
* @brief value used to reset the LPM mode
*/
#define UTIL_LPM_NO_BIT_SET (0UL)
/**
* @}
*/
/* Private macros ------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/** @defgroup TINY_LPM_Private_variables TINY LPM private variables
* @{
*/
/**
* @brief value used to represent the LPM state of stop mode
*/
static UTIL_LPM_bm_t StopModeDisable = UTIL_LPM_NO_BIT_SET;
/**
* @brief value used to represent the LPM state of off mode
*/
static UTIL_LPM_bm_t OffModeDisable = UTIL_LPM_NO_BIT_SET;
/**
* @}
*/
/* Global variables ----------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/* Functions Definition ------------------------------------------------------*/
/** @addtogroup TINY_LPM_Exported_function
* @{
*/
void UTIL_LPM_Init( void )
{
StopModeDisable = UTIL_LPM_NO_BIT_SET;
OffModeDisable = UTIL_LPM_NO_BIT_SET;
UTIL_LPM_INIT_CRITICAL_SECTION( );
}
void UTIL_LPM_DeInit( void )
{
}
void UTIL_LPM_SetStopMode( UTIL_LPM_bm_t lpm_id_bm, UTIL_LPM_State_t state )
{
UTIL_LPM_ENTER_CRITICAL_SECTION( );
switch( state )
{
case UTIL_LPM_DISABLE:
{
StopModeDisable |= lpm_id_bm;
break;
}
case UTIL_LPM_ENABLE:
{
StopModeDisable &= ( ~lpm_id_bm );
break;
}
default :
{
break;
}
}
UTIL_LPM_EXIT_CRITICAL_SECTION( );
}
void UTIL_LPM_SetOffMode( UTIL_LPM_bm_t lpm_id_bm, UTIL_LPM_State_t state )
{
UTIL_LPM_ENTER_CRITICAL_SECTION( );
switch(state)
{
case UTIL_LPM_DISABLE:
{
OffModeDisable |= lpm_id_bm;
break;
}
case UTIL_LPM_ENABLE:
{
OffModeDisable &= ( ~lpm_id_bm );
break;
}
default :
{
break;
}
}
UTIL_LPM_EXIT_CRITICAL_SECTION( );
}
UTIL_LPM_Mode_t UTIL_LPM_GetMode( void )
{
UTIL_LPM_Mode_t mode_selected;
UTIL_LPM_ENTER_CRITICAL_SECTION( );
if( StopModeDisable != UTIL_LPM_NO_BIT_SET )
{
/**
* At least one user disallows Stop Mode
*/
mode_selected = UTIL_LPM_SLEEPMODE;
}
else
{
if( OffModeDisable != UTIL_LPM_NO_BIT_SET )
{
/**
* At least one user disallows Off Mode
*/
mode_selected = UTIL_LPM_STOPMODE;
}
else
{
mode_selected = UTIL_LPM_OFFMODE;
}
}
UTIL_LPM_EXIT_CRITICAL_SECTION( );
return mode_selected;
}
void UTIL_LPM_EnterLowPower( void )
{
UTIL_LPM_ENTER_CRITICAL_SECTION_ELP( );
if( StopModeDisable != UTIL_LPM_NO_BIT_SET )
{
/**
* At least one user disallows Stop Mode
* SLEEP mode is required
*/
UTIL_PowerDriver.EnterSleepMode( );
UTIL_PowerDriver.ExitSleepMode( );
}
else
{
if( OffModeDisable != UTIL_LPM_NO_BIT_SET )
{
/**
* At least one user disallows Off Mode
* STOP mode is required
*/
UTIL_PowerDriver.EnterStopMode( );
UTIL_PowerDriver.ExitStopMode( );
}
else
{
/**
* OFF mode is required
*/
UTIL_PowerDriver.EnterOffMode( );
UTIL_PowerDriver.ExitOffMode( );
}
}
UTIL_LPM_EXIT_CRITICAL_SECTION_ELP( );
}
/**
* @}
*/
/**
* @}
*/

View File

@ -0,0 +1,167 @@
/**
******************************************************************************
* @file stm32_lpm.h
* @author MCD Application Team
* @brief Header for stm32_lpm.c module
******************************************************************************
* @attention
*
* <h2><center>&copy; Copyright (c) 2019 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef STM32_TINY_LPM_H
#define STM32_TINY_LPM_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "stdint.h"
/** @defgroup TINY_LPM TINY LPM
* @{
*/
/* Exported typedef ---------------------------------------------------------*/
/** @defgroup TINY_LPM_Exported_typedef TINY LPM exported typedef
* @{
*/
/**
* @brief type definition to represent the bit mask of an LPM mode
*/
typedef uint32_t UTIL_LPM_bm_t;
/**
* @brief type definition to represent value of an LPM mode
*/
typedef enum
{
UTIL_LPM_ENABLE=0,
UTIL_LPM_DISABLE,
} UTIL_LPM_State_t;
/**
* @brief type definition to represent the different type of LPM mode
*/
typedef enum
{
UTIL_LPM_SLEEPMODE,
UTIL_LPM_STOPMODE,
UTIL_LPM_OFFMODE,
} UTIL_LPM_Mode_t;
/**
* @}
*/
/** @defgroup TINY_LPM_Exported_struct TINY LPM exported struct
* @{
*/
/**
* @brief LPM driver definition
*/
struct UTIL_LPM_Driver_s
{
void (*EnterSleepMode) ( void ); /*!<function to enter the sleep mode */
void (*ExitSleepMode) ( void ); /*!<function to exit the sleep mode */
void (*EnterStopMode) ( void ); /*!<function to enter the stop mode */
void (*ExitStopMode) ( void ); /*!<function to exit the stop mode */
void (*EnterOffMode) ( void ); /*!<function to enter the off mode */
void (*ExitOffMode) ( void ); /*!<function to exit the off mode */
};
/**
* @}
*/
/* External variables --------------------------------------------------------*/
/** @defgroup TINY_LPM_Exported_struct TINY LPM exported struct
* @{
*/
/**
* @brief LPM driver
*
* @note This structure is defined and initialized in the specific platform
* power implementation
*/
extern const struct UTIL_LPM_Driver_s UTIL_PowerDriver;
/**
* @}
*/
/* Exported macros -----------------------------------------------------------*/
/* Exported functions ------------------------------------------------------- */
/** @defgroup TINY_LPM_Exported_function TINY LPM exported functions
* @{
*/
/**
* @brief This API Initializes the LPM resources.
*/
void UTIL_LPM_Init( void );
/**
* @brief This API Un-Initializes the LPM resources.
*/
void UTIL_LPM_DeInit( void );
/**
* @brief This API returns the Low Power Mode selected that will be applied when the system will enter low power mode
* if there is no update between the time the mode is read with this API and the time the system enters
* low power mode.
* @retval the LPM mode based on @ref UTIL_LPM_Mode_t
*/
UTIL_LPM_Mode_t UTIL_LPM_GetMode( void );
/**
* @brief This API notifies the low power manager if the specified user allows the Stop mode or not.
* The default mode selection for all users is Stop Mode enabled
* @param lpm_id_bm: identifier of the user ( 1 bit per user )
* @param state: Specify whether StopMode is allowed or not by this user
*/
void UTIL_LPM_SetStopMode( UTIL_LPM_bm_t lpm_id_bm, UTIL_LPM_State_t state );
/**
* @brief This API notifies the low power manager if the specified user allows the Off mode or not.
* The default mode selection for all users is Off mode enabled
* @param lpm_id_bm: identifier of the user ( 1 bit per user )
* @param state: Specify whether OffMode is allowed or not by this user
*/
void UTIL_LPM_SetOffMode( UTIL_LPM_bm_t lpm_id_bm, UTIL_LPM_State_t state );
/**
* @brief This API is called by the low power manager in a critical section (PRIMASK bit set) to allow the
* application to implement dedicated code before entering Low Power Mode
*/
void UTIL_LPM_EnterLowPower( void );
/**
*@}
*/
/**
*@}
*/
#ifdef __cplusplus
}
#endif
#endif /* STM32_TINY_LPM_H */

View File

@ -0,0 +1,131 @@
/*******************************************************************************
* @file stm32_lpm_if.c
* @author MCD Application Team
* @brief Low layer function to enter/exit low power modes (stop, sleep)
******************************************************************************
* @attention
*
* <h2><center>&copy; Copyright (c) 2019 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include "stm32_lpm_if.h"
#include "stm32_lpm.h"
/** @addtogroup TINY_LPM_IF
* @{
*/
/* USER CODE BEGIN include */
/* USER CODE END include */
/* Exported variables --------------------------------------------------------*/
/** @defgroup TINY_LPM_IF_Exported_varaibles TINY LPM IF exported variables
* @{
*/
/**
* @brief variable to provide all the functions corresponding to the different low power modes.
*/
const struct UTIL_LPM_Driver_s UTIL_PowerDriver =
{
PWR_EnterSleepMode,
PWR_ExitSleepMode,
PWR_EnterStopMode,
PWR_ExitStopMode,
PWR_EnterOffMode,
PWR_ExitOffMode,
};
/**
* @}
*/
/* Private function prototypes -----------------------------------------------*/
/* USER CODE BEGIN Private_Function_Prototypes */
/* USER CODE END Private_Function_Prototypes */
/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN Private_Typedef */
/* USER CODE END Private_Typedef */
/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN Private_Define */
/* USER CODE END Private_Define */
/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN Private_Macro */
/* USER CODE END Private_Macro */
/* Private variables ---------------------------------------------------------*/
/* USER CODE BEGIN Private_Variables */
/* USER CODE END Private_Variables */
/** @addtogroup TINY_LPM_IF_Exported_functions
* @{
*/
void PWR_EnterOffMode( void )
{
/* USER CODE BEGIN PWR_EnterOffMode */
/* USER CODE END PWR_EnterOffMode */
}
void PWR_ExitOffMode( void )
{
/* USER CODE BEGIN PWR_ExitOffMode */
/* USER CODE END PWR_ExitOffMode */
}
void PWR_EnterStopMode( void )
{
/* USER CODE BEGIN PWR_EnterStopMode */
/* USER CODE END PWR_EnterStopMode */
}
void PWR_ExitStopMode( void )
{
/* USER CODE BEGIN PWR_ExitStopMode */
/* USER CODE END PWR_ExitStopMode */
}
void PWR_EnterSleepMode( void )
{
/* USER CODE BEGIN PWR_EnterSleepMode */
/* USER CODE END PWR_EnterSleepMode */
}
void PWR_ExitSleepMode( void )
{
/* USER CODE BEGIN PWR_ExitSleepMode */
/* USER CODE END PWR_ExitSleepMode */
}
/* USER CODE BEGIN Private_Functions */
/* USER CODE END Private_Functions */
/**
* @}
*/
/**
* @}
*/

View File

@ -0,0 +1,79 @@
/**
******************************************************************************
* @file stm32_lpm_if.h
* @brief Header for stm32_lpm_f.c module (device specific LP management)
******************************************************************************
* @attention
*
* <h2><center>&copy; Copyright (c) 2019 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef STM32_TINY_LPM_IF_H
#define STM32_TINY_LPM_IF_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
/** @defgroup TINY_LPM_IF TINY LPM IF
* @{
*/
/* Exported Functions ------------------------------------------------------------------*/
/** @defgroup TINY_LPM_IF_Exported_functions TINY LPM IF Exported functions
* @{
*/
/**
* @brief Enters Low Power Off Mode
*/
void PWR_EnterOffMode( void );
/**
* @brief Exits Low Power Off Mode
*/
void PWR_ExitOffMode( void );
/**
* @brief Enters Low Power Stop Mode
*/
void PWR_EnterStopMode( void );
/**
* @brief Exits Low Power Stop Mode
*/
void PWR_ExitStopMode( void );
/**
* @brief Enters Low Power Sleep Mode
*/
void PWR_EnterSleepMode( void );
/**
* @brief Exits Low Power Sleep Mode
*/
void PWR_ExitSleepMode( void );
/**
* @}
*/
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif /* STM32_TINY_LPM_IF_H */