1 /*! 2 * \file lpm-board.c 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 #include <stdint.h> 26 #include "stm32l4xx.h" 27 #include "utilities.h" 28 #include "lpm-board.h" 29 30 static uint32_t StopModeDisable = 0; 31 static uint32_t OffModeDisable = 0; 32 LpmSetOffMode(LpmId_t id,LpmSetMode_t mode)33void LpmSetOffMode( LpmId_t id, LpmSetMode_t mode ) 34 { 35 CRITICAL_SECTION_BEGIN( ); 36 37 switch( mode ) 38 { 39 case LPM_DISABLE: 40 { 41 OffModeDisable |= ( uint32_t )id; 42 break; 43 } 44 case LPM_ENABLE: 45 { 46 OffModeDisable &= ~( uint32_t )id; 47 break; 48 } 49 default: 50 { 51 break; 52 } 53 } 54 55 CRITICAL_SECTION_END( ); 56 return; 57 } 58 LpmSetStopMode(LpmId_t id,LpmSetMode_t mode)59void LpmSetStopMode( LpmId_t id, LpmSetMode_t mode ) 60 { 61 CRITICAL_SECTION_BEGIN( ); 62 63 switch( mode ) 64 { 65 case LPM_DISABLE: 66 { 67 StopModeDisable |= ( uint32_t )id; 68 break; 69 } 70 case LPM_ENABLE: 71 { 72 StopModeDisable &= ~( uint32_t )id; 73 break; 74 } 75 default: 76 { 77 break; 78 } 79 } 80 81 CRITICAL_SECTION_END( ); 82 return; 83 } 84 LpmEnterLowPower(void)85void LpmEnterLowPower( void ) 86 { 87 if( StopModeDisable != 0 ) 88 { 89 /*! 90 * SLEEP mode is required 91 */ 92 LpmEnterSleepMode( ); 93 LpmExitSleepMode( ); 94 } 95 else 96 { 97 if( OffModeDisable != 0 ) 98 { 99 /*! 100 * STOP mode is required 101 */ 102 LpmEnterStopMode( ); 103 LpmExitStopMode( ); 104 } 105 else 106 { 107 /*! 108 * OFF mode is required 109 */ 110 LpmEnterOffMode( ); 111 LpmExitOffMode( ); 112 } 113 } 114 return; 115 } 116 LpmGetMode(void)117LpmGetMode_t LpmGetMode(void) 118 { 119 LpmGetMode_t mode; 120 121 CRITICAL_SECTION_BEGIN( ); 122 123 if( StopModeDisable != 0 ) 124 { 125 mode = LPM_SLEEP_MODE; 126 } 127 else 128 { 129 if( OffModeDisable != 0 ) 130 { 131 mode = LPM_STOP_MODE; 132 } 133 else 134 { 135 mode = LPM_OFF_MODE; 136 } 137 } 138 139 CRITICAL_SECTION_END( ); 140 return mode; 141 } 142 LpmEnterSleepMode(void)143__weak void LpmEnterSleepMode( void ) 144 { 145 } 146 LpmExitSleepMode(void)147__weak void LpmExitSleepMode( void ) 148 { 149 } 150 LpmEnterStopMode(void)151__weak void LpmEnterStopMode( void ) 152 { 153 } 154 LpmExitStopMode(void)155__weak void LpmExitStopMode( void ) 156 { 157 } 158 LpmEnterOffMode(void)159__weak void LpmEnterOffMode( void ) 160 { 161 } 162 LpmExitOffMode(void)163__weak void LpmExitOffMode( void ) 164 { 165 } 166