A demo application for HXC900 LoRaWAN module using Nucleo-L053R8.

Dependencies:   mbed

Committer:
fahadmirza
Date:
Thu Jul 12 00:50:48 2018 +0000
Revision:
0:a0c5877bd360
Porting complete!

Who changed what in which revision?

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