Kashish Haresh Shah
/
HXCClientShield
HXC Client Shield Repository.
Utilities/low_power_manager.c@0:bacc6e701fb4, 2021-03-29 (annotated)
- Committer:
- kashish_mbed
- Date:
- Mon Mar 29 15:37:08 2021 +0000
- Revision:
- 0:bacc6e701fb4
Initial Commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kashish_mbed | 0:bacc6e701fb4 | 1 | /** |
kashish_mbed | 0:bacc6e701fb4 | 2 | ****************************************************************************** |
kashish_mbed | 0:bacc6e701fb4 | 3 | * @file low_power_manager.c |
kashish_mbed | 0:bacc6e701fb4 | 4 | * @author MCD Application Team |
kashish_mbed | 0:bacc6e701fb4 | 5 | * @version V1.1.4 |
kashish_mbed | 0:bacc6e701fb4 | 6 | * @date 08-January-2018 |
kashish_mbed | 0:bacc6e701fb4 | 7 | * @brief Low Power Manager |
kashish_mbed | 0:bacc6e701fb4 | 8 | ****************************************************************************** |
kashish_mbed | 0:bacc6e701fb4 | 9 | * @attention |
kashish_mbed | 0:bacc6e701fb4 | 10 | * |
kashish_mbed | 0:bacc6e701fb4 | 11 | * <h2><center>© Copyright (c) 2016 STMicroelectronics International N.V. |
kashish_mbed | 0:bacc6e701fb4 | 12 | * All rights reserved.</center></h2> |
kashish_mbed | 0:bacc6e701fb4 | 13 | * |
kashish_mbed | 0:bacc6e701fb4 | 14 | * Redistribution and use in source and binary forms, with or without |
kashish_mbed | 0:bacc6e701fb4 | 15 | * modification, are permitted, provided that the following conditions are met: |
kashish_mbed | 0:bacc6e701fb4 | 16 | * |
kashish_mbed | 0:bacc6e701fb4 | 17 | * 1. Redistribution of source code must retain the above copyright notice, |
kashish_mbed | 0:bacc6e701fb4 | 18 | * this list of conditions and the following disclaimer. |
kashish_mbed | 0:bacc6e701fb4 | 19 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
kashish_mbed | 0:bacc6e701fb4 | 20 | * this list of conditions and the following disclaimer in the documentation |
kashish_mbed | 0:bacc6e701fb4 | 21 | * and/or other materials provided with the distribution. |
kashish_mbed | 0:bacc6e701fb4 | 22 | * 3. Neither the name of STMicroelectronics nor the names of other |
kashish_mbed | 0:bacc6e701fb4 | 23 | * contributors to this software may be used to endorse or promote products |
kashish_mbed | 0:bacc6e701fb4 | 24 | * derived from this software without specific written permission. |
kashish_mbed | 0:bacc6e701fb4 | 25 | * 4. This software, including modifications and/or derivative works of this |
kashish_mbed | 0:bacc6e701fb4 | 26 | * software, must execute solely and exclusively on microcontroller or |
kashish_mbed | 0:bacc6e701fb4 | 27 | * microprocessor devices manufactured by or for STMicroelectronics. |
kashish_mbed | 0:bacc6e701fb4 | 28 | * 5. Redistribution and use of this software other than as permitted under |
kashish_mbed | 0:bacc6e701fb4 | 29 | * this license is void and will automatically terminate your rights under |
kashish_mbed | 0:bacc6e701fb4 | 30 | * this license. |
kashish_mbed | 0:bacc6e701fb4 | 31 | * |
kashish_mbed | 0:bacc6e701fb4 | 32 | * THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS" |
kashish_mbed | 0:bacc6e701fb4 | 33 | * AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT |
kashish_mbed | 0:bacc6e701fb4 | 34 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A |
kashish_mbed | 0:bacc6e701fb4 | 35 | * PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY |
kashish_mbed | 0:bacc6e701fb4 | 36 | * RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT |
kashish_mbed | 0:bacc6e701fb4 | 37 | * SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
kashish_mbed | 0:bacc6e701fb4 | 38 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
kashish_mbed | 0:bacc6e701fb4 | 39 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, |
kashish_mbed | 0:bacc6e701fb4 | 40 | * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
kashish_mbed | 0:bacc6e701fb4 | 41 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
kashish_mbed | 0:bacc6e701fb4 | 42 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, |
kashish_mbed | 0:bacc6e701fb4 | 43 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
kashish_mbed | 0:bacc6e701fb4 | 44 | * |
kashish_mbed | 0:bacc6e701fb4 | 45 | ****************************************************************************** |
kashish_mbed | 0:bacc6e701fb4 | 46 | */ |
kashish_mbed | 0:bacc6e701fb4 | 47 | |
kashish_mbed | 0:bacc6e701fb4 | 48 | /* Includes ------------------------------------------------------------------*/ |
kashish_mbed | 0:bacc6e701fb4 | 49 | #include "hw.h" |
kashish_mbed | 0:bacc6e701fb4 | 50 | #include "low_power_manager.h" |
kashish_mbed | 0:bacc6e701fb4 | 51 | |
kashish_mbed | 0:bacc6e701fb4 | 52 | /* Private typedef -----------------------------------------------------------*/ |
kashish_mbed | 0:bacc6e701fb4 | 53 | /* Private defines -----------------------------------------------------------*/ |
kashish_mbed | 0:bacc6e701fb4 | 54 | /* Private macros ------------------------------------------------------------*/ |
kashish_mbed | 0:bacc6e701fb4 | 55 | /* Private variables ---------------------------------------------------------*/ |
kashish_mbed | 0:bacc6e701fb4 | 56 | static uint32_t StopModeDisable = 0; |
kashish_mbed | 0:bacc6e701fb4 | 57 | static uint32_t OffModeDisable = 0; |
kashish_mbed | 0:bacc6e701fb4 | 58 | |
kashish_mbed | 0:bacc6e701fb4 | 59 | /* Global variables ----------------------------------------------------------*/ |
kashish_mbed | 0:bacc6e701fb4 | 60 | /* Private function prototypes -----------------------------------------------*/ |
kashish_mbed | 0:bacc6e701fb4 | 61 | /* Functions Definition ------------------------------------------------------*/ |
kashish_mbed | 0:bacc6e701fb4 | 62 | void LPM_SetOffMode(LPM_Id_t id, LPM_SetMode_t mode) |
kashish_mbed | 0:bacc6e701fb4 | 63 | { |
kashish_mbed | 0:bacc6e701fb4 | 64 | BACKUP_PRIMASK(); |
kashish_mbed | 0:bacc6e701fb4 | 65 | |
kashish_mbed | 0:bacc6e701fb4 | 66 | DISABLE_IRQ( ); |
kashish_mbed | 0:bacc6e701fb4 | 67 | |
kashish_mbed | 0:bacc6e701fb4 | 68 | |
kashish_mbed | 0:bacc6e701fb4 | 69 | switch(mode) |
kashish_mbed | 0:bacc6e701fb4 | 70 | { |
kashish_mbed | 0:bacc6e701fb4 | 71 | case LPM_Disable: |
kashish_mbed | 0:bacc6e701fb4 | 72 | { |
kashish_mbed | 0:bacc6e701fb4 | 73 | OffModeDisable |= (uint32_t)id; |
kashish_mbed | 0:bacc6e701fb4 | 74 | break; |
kashish_mbed | 0:bacc6e701fb4 | 75 | } |
kashish_mbed | 0:bacc6e701fb4 | 76 | case LPM_Enable: |
kashish_mbed | 0:bacc6e701fb4 | 77 | { |
kashish_mbed | 0:bacc6e701fb4 | 78 | OffModeDisable &= ~(uint32_t)id; |
kashish_mbed | 0:bacc6e701fb4 | 79 | break; |
kashish_mbed | 0:bacc6e701fb4 | 80 | } |
kashish_mbed | 0:bacc6e701fb4 | 81 | default: |
kashish_mbed | 0:bacc6e701fb4 | 82 | break; |
kashish_mbed | 0:bacc6e701fb4 | 83 | } |
kashish_mbed | 0:bacc6e701fb4 | 84 | |
kashish_mbed | 0:bacc6e701fb4 | 85 | RESTORE_PRIMASK( ); |
kashish_mbed | 0:bacc6e701fb4 | 86 | |
kashish_mbed | 0:bacc6e701fb4 | 87 | return; |
kashish_mbed | 0:bacc6e701fb4 | 88 | } |
kashish_mbed | 0:bacc6e701fb4 | 89 | |
kashish_mbed | 0:bacc6e701fb4 | 90 | void LPM_SetStopMode(LPM_Id_t id, LPM_SetMode_t mode) |
kashish_mbed | 0:bacc6e701fb4 | 91 | { |
kashish_mbed | 0:bacc6e701fb4 | 92 | BACKUP_PRIMASK(); |
kashish_mbed | 0:bacc6e701fb4 | 93 | |
kashish_mbed | 0:bacc6e701fb4 | 94 | DISABLE_IRQ( ); |
kashish_mbed | 0:bacc6e701fb4 | 95 | |
kashish_mbed | 0:bacc6e701fb4 | 96 | |
kashish_mbed | 0:bacc6e701fb4 | 97 | switch(mode) |
kashish_mbed | 0:bacc6e701fb4 | 98 | { |
kashish_mbed | 0:bacc6e701fb4 | 99 | case LPM_Disable: |
kashish_mbed | 0:bacc6e701fb4 | 100 | { |
kashish_mbed | 0:bacc6e701fb4 | 101 | StopModeDisable |= (uint32_t)id; |
kashish_mbed | 0:bacc6e701fb4 | 102 | break; |
kashish_mbed | 0:bacc6e701fb4 | 103 | } |
kashish_mbed | 0:bacc6e701fb4 | 104 | case LPM_Enable: |
kashish_mbed | 0:bacc6e701fb4 | 105 | { |
kashish_mbed | 0:bacc6e701fb4 | 106 | StopModeDisable &= ~(uint32_t)id; |
kashish_mbed | 0:bacc6e701fb4 | 107 | break; |
kashish_mbed | 0:bacc6e701fb4 | 108 | } |
kashish_mbed | 0:bacc6e701fb4 | 109 | default: |
kashish_mbed | 0:bacc6e701fb4 | 110 | break; |
kashish_mbed | 0:bacc6e701fb4 | 111 | } |
kashish_mbed | 0:bacc6e701fb4 | 112 | RESTORE_PRIMASK( ); |
kashish_mbed | 0:bacc6e701fb4 | 113 | |
kashish_mbed | 0:bacc6e701fb4 | 114 | return; |
kashish_mbed | 0:bacc6e701fb4 | 115 | } |
kashish_mbed | 0:bacc6e701fb4 | 116 | |
kashish_mbed | 0:bacc6e701fb4 | 117 | void LPM_EnterLowPower(void) |
kashish_mbed | 0:bacc6e701fb4 | 118 | { |
kashish_mbed | 0:bacc6e701fb4 | 119 | if( StopModeDisable ) |
kashish_mbed | 0:bacc6e701fb4 | 120 | { |
kashish_mbed | 0:bacc6e701fb4 | 121 | /** |
kashish_mbed | 0:bacc6e701fb4 | 122 | * SLEEP mode is required |
kashish_mbed | 0:bacc6e701fb4 | 123 | */ |
kashish_mbed | 0:bacc6e701fb4 | 124 | LPM_EnterSleepMode(); |
kashish_mbed | 0:bacc6e701fb4 | 125 | LPM_ExitSleepMode(); |
kashish_mbed | 0:bacc6e701fb4 | 126 | } |
kashish_mbed | 0:bacc6e701fb4 | 127 | else |
kashish_mbed | 0:bacc6e701fb4 | 128 | { |
kashish_mbed | 0:bacc6e701fb4 | 129 | if( OffModeDisable ) |
kashish_mbed | 0:bacc6e701fb4 | 130 | { |
kashish_mbed | 0:bacc6e701fb4 | 131 | /** |
kashish_mbed | 0:bacc6e701fb4 | 132 | * STOP mode is required |
kashish_mbed | 0:bacc6e701fb4 | 133 | */ |
kashish_mbed | 0:bacc6e701fb4 | 134 | LPM_EnterStopMode(); |
kashish_mbed | 0:bacc6e701fb4 | 135 | LPM_ExitStopMode(); |
kashish_mbed | 0:bacc6e701fb4 | 136 | } |
kashish_mbed | 0:bacc6e701fb4 | 137 | else |
kashish_mbed | 0:bacc6e701fb4 | 138 | { |
kashish_mbed | 0:bacc6e701fb4 | 139 | /** |
kashish_mbed | 0:bacc6e701fb4 | 140 | * OFF mode is required |
kashish_mbed | 0:bacc6e701fb4 | 141 | */ |
kashish_mbed | 0:bacc6e701fb4 | 142 | LPM_EnterOffMode(); |
kashish_mbed | 0:bacc6e701fb4 | 143 | LPM_ExitOffMode(); |
kashish_mbed | 0:bacc6e701fb4 | 144 | } |
kashish_mbed | 0:bacc6e701fb4 | 145 | } |
kashish_mbed | 0:bacc6e701fb4 | 146 | |
kashish_mbed | 0:bacc6e701fb4 | 147 | return; |
kashish_mbed | 0:bacc6e701fb4 | 148 | } |
kashish_mbed | 0:bacc6e701fb4 | 149 | |
kashish_mbed | 0:bacc6e701fb4 | 150 | LPM_GetMode_t LPM_GetMode(void) |
kashish_mbed | 0:bacc6e701fb4 | 151 | { |
kashish_mbed | 0:bacc6e701fb4 | 152 | LPM_GetMode_t mode_selected; |
kashish_mbed | 0:bacc6e701fb4 | 153 | |
kashish_mbed | 0:bacc6e701fb4 | 154 | BACKUP_PRIMASK(); |
kashish_mbed | 0:bacc6e701fb4 | 155 | |
kashish_mbed | 0:bacc6e701fb4 | 156 | DISABLE_IRQ( ); |
kashish_mbed | 0:bacc6e701fb4 | 157 | |
kashish_mbed | 0:bacc6e701fb4 | 158 | if(StopModeDisable ) |
kashish_mbed | 0:bacc6e701fb4 | 159 | { |
kashish_mbed | 0:bacc6e701fb4 | 160 | mode_selected = LPM_SleepMode; |
kashish_mbed | 0:bacc6e701fb4 | 161 | } |
kashish_mbed | 0:bacc6e701fb4 | 162 | else |
kashish_mbed | 0:bacc6e701fb4 | 163 | { |
kashish_mbed | 0:bacc6e701fb4 | 164 | if(OffModeDisable) |
kashish_mbed | 0:bacc6e701fb4 | 165 | { |
kashish_mbed | 0:bacc6e701fb4 | 166 | mode_selected = LPM_StopMode; |
kashish_mbed | 0:bacc6e701fb4 | 167 | } |
kashish_mbed | 0:bacc6e701fb4 | 168 | else |
kashish_mbed | 0:bacc6e701fb4 | 169 | { |
kashish_mbed | 0:bacc6e701fb4 | 170 | mode_selected = LPM_OffMode; |
kashish_mbed | 0:bacc6e701fb4 | 171 | } |
kashish_mbed | 0:bacc6e701fb4 | 172 | } |
kashish_mbed | 0:bacc6e701fb4 | 173 | |
kashish_mbed | 0:bacc6e701fb4 | 174 | RESTORE_PRIMASK( ); |
kashish_mbed | 0:bacc6e701fb4 | 175 | |
kashish_mbed | 0:bacc6e701fb4 | 176 | return mode_selected; |
kashish_mbed | 0:bacc6e701fb4 | 177 | } |
kashish_mbed | 0:bacc6e701fb4 | 178 | |
kashish_mbed | 0:bacc6e701fb4 | 179 | __weak void LPM_EnterSleepMode(void) {} |
kashish_mbed | 0:bacc6e701fb4 | 180 | __weak void LPM_ExitSleepMode(void) {} |
kashish_mbed | 0:bacc6e701fb4 | 181 | __weak void LPM_EnterStopMode(void) {} |
kashish_mbed | 0:bacc6e701fb4 | 182 | __weak void LPM_ExitStopMode(void) {} |
kashish_mbed | 0:bacc6e701fb4 | 183 | __weak void LPM_EnterOffMode(void) {} |
kashish_mbed | 0:bacc6e701fb4 | 184 | __weak void LPM_ExitOffMode(void) {} |
kashish_mbed | 0:bacc6e701fb4 | 185 | |
kashish_mbed | 0:bacc6e701fb4 | 186 | |
kashish_mbed | 0:bacc6e701fb4 | 187 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
kashish_mbed | 0:bacc6e701fb4 | 188 |