Implement a secure ICS protocol targeting LoRa Node151 microcontroller for controlling irrigation.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

166 lines
2.9 KiB

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