1 /*!
2  * \file      lpm-board.h
3  *
4  * \brief     Target board low power modes management
5  *
6  * \copyright Revised BSD License, see section \ref LICENSE.
7  *
8  * \code
9  *                ______                              _
10  *               / _____)             _              | |
11  *              ( (____  _____ ____ _| |_ _____  ____| |__
12  *               \____ \| ___ |    (_   _) ___ |/ ___)  _ \
13  *               _____) ) ____| | | || |_| ____( (___| | | |
14  *              (______/|_____)_|_|_| \__)_____)\____)_| |_|
15  *              (C)2013-2017 Semtech - STMicroelectronics
16  *
17  * \endcode
18  *
19  * \author    Miguel Luis ( Semtech )
20  *
21  * \author    Gregory Cristian ( Semtech )
22  *
23  * \author    MCD Application Team (C)( STMicroelectronics International )
24  */
25 #ifndef __LPM_BOARD_H__
26 #define __LPM_BOARD_H__
27 
28 
29 #ifdef __cplusplus
30 extern "C"
31 {
32 #endif
33 
34 #include "board-config.h"
35 
36 /*!
37  * Low power manager configuration
38  */
39 typedef enum
40 {
41     LPM_APPLI_ID   =                                ( 1 << 0 ),
42     LPM_LIB_ID     =                                ( 1 << 1 ),
43     LPM_RTC_ID     =                                ( 1 << 2 ),
44     LPM_GPS_ID     =                                ( 1 << 3 ),
45     LPM_UART_RX_ID =                                ( 1 << 4 ),
46     LPM_UART_TX_ID =                                ( 1 << 5 ),
47 } LpmId_t;
48 
49 /*!
50  * Low Power Mode selected
51  */
52 typedef enum
53 {
54     LPM_ENABLE = 0,
55     LPM_DISABLE,
56 } LpmSetMode_t;
57 
58 typedef enum
59 {
60     LPM_SLEEP_MODE,
61     LPM_STOP_MODE,
62     LPM_OFF_MODE,
63 } LpmGetMode_t;
64 
65 /*!
66  * \brief  This API returns the Low Power Mode selected that will be applied when the system will enter low power mode
67  *         if there is no update between the time the mode is read with this API and the time the system enters
68  *         low power mode.
69  *
70  * \retval mode Selected low power mode
71  */
72 LpmGetMode_t LpmGetMode( void );
73 
74 /*!
75  * \brief  This API notifies the low power manager if the specified user allows the Stop mode or not.
76  *         When the application does not require the system clock, it enters Stop Mode if at least one user disallow
77  *         Off Mode. Otherwise, it enters Off Mode.
78  *         The default mode selection for all users is Off mode enabled
79  *
80  * \param [IN] id   Process Id
81  * \param [IN] mode Selected mode
82  */
83 void LpmSetStopMode( LpmId_t id, LpmSetMode_t mode );
84 
85 /*!
86  * \brief  This API notifies the low power manager if the specified user allows the Off mode or not.
87  *         When the application does not require the system clock, it enters Stop Mode if at least one user disallow
88  *         Off Mode. Otherwise, it enters Off Mode.
89  *         The default mode selection for all users is Off mode enabled
90  *
91  * \param [IN] id   Process Id
92  * \param [IN] mode Selected mode
93  */
94 void LpmSetOffMode(LpmId_t id, LpmSetMode_t mode );
95 
96 /*!
97  * \brief  This API shall be used by the application when there is no more code to execute so that the system may
98  *         enter low-power mode. The mode selected depends on the information received from LpmOffModeSelection( ) and
99  *         LpmSysclockRequest( )
100  *         This function shall be called in critical section
101  */
102 void LpmEnterLowPower( void );
103 
104 /*!
105  * \brief  This API is called by the low power manager in a critical section (PRIMASK bit set) to allow the
106  *         application to implement dedicated code before entering Sleep Mode
107  */
108 void LpmEnterSleepMode( void );
109 
110 /*!
111  * \brief  This API is called by the low power manager in a critical section (PRIMASK bit set) to allow the
112  *         application to implement dedicated code before getting out from Sleep Mode
113  */
114 void LpmExitSleepMode( void );
115 
116 /*!
117  * \brief  This API is called by the low power manager in a critical section (PRIMASK bit set) to allow the
118  *         application to implement dedicated code before entering Stop Mode
119  */
120 void LpmEnterStopMode( void );
121 
122 /*!
123  * \brief  This API is called by the low power manager in a critical section (PRIMASK bit set) to allow the
124  *         application to implement dedicated code before getting out from Stop Mode. This is where the application
125  *         should reconfigure the clock tree when needed
126  */
127 void LpmExitStopMode( void );
128 
129 /*!
130  * \brief  This API is called by the low power manager in a critical section (PRIMASK bit set) to allow the
131  *         application to implement dedicated code before entering Off mode. This is where the application could save
132  *         data in the retention memory as the RAM memory content will be lost
133  */
134 void LpmEnterOffMode( void );
135 
136 /*!
137  * @brief  This API is called by the low power manager in a critical section (PRIMASK bit set) to allow the
138  *         application to implement dedicated code before getting out from Off mode. This can only happen when the
139  *         Off mode is finally not entered. In that case, the application may reverse some configurations done before
140  *         entering Off mode. When Off mode is successful, the system is reset when getting out from this low-power mode
141  */
142 void LpmExitOffMode( void );
143 
144 #ifdef __cplusplus
145 }
146 #endif
147 
148 #endif /*__LPM_BOARD_H__ */
149