stm8l15x_wfe.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  1. /**
  2. ******************************************************************************
  3. * @file stm8l15x_wfe.c
  4. * @author MCD Application Team
  5. * @version V1.6.1
  6. * @date 30-September-2014
  7. * @brief This file provides firmware functions to manage the following
  8. * functionalities of the Wait for Event (WFE) peripheral:
  9. * - WFE Source configuration and management
  10. *
  11. * @verbatim
  12. *
  13. * ===================================================================
  14. * WFE specific features
  15. * ===================================================================
  16. *
  17. * Wait for event mode (WFE) stops the CPU but allows the other peripherals
  18. * and interrupt controller to continue running.
  19. * This mode is entered from Run mode by executing a WFE instruction.
  20. * Peripheral events can be generated by the timers, serial interfaces,
  21. * DMA controller, comparators and I/O ports.
  22. * These are enabled by using the WFE_WakeUpSourceEventCmd() function.
  23. *
  24. * When a peripheral event is enabled, the corresponding interrupts are
  25. * not served and you have to clear the corresponding flag status.
  26. *
  27. * There are two ways to wake up the CPU from WFE mode:
  28. * - Interrupts: When an interrupt occurs, the CPU wakes up from WFE mode
  29. * serves the interrupt then goes back to WFE mode.
  30. * - Wake up event: when a wake up event occurs, the CPU wakes up and
  31. * resumes processing, in this case and to save time and power consumption
  32. * there is no context save/restore activity.
  33. *
  34. *
  35. * @endverbatim
  36. *
  37. ******************************************************************************
  38. * @attention
  39. *
  40. * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
  41. *
  42. * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
  43. * You may not use this file except in compliance with the License.
  44. * You may obtain a copy of the License at:
  45. *
  46. * http://www.st.com/software_license_agreement_liberty_v2
  47. *
  48. * Unless required by applicable law or agreed to in writing, software
  49. * distributed under the License is distributed on an "AS IS" BASIS,
  50. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  51. * See the License for the specific language governing permissions and
  52. * limitations under the License.
  53. *
  54. ******************************************************************************
  55. */
  56. /* Includes ------------------------------------------------------------------*/
  57. #include "stm8l15x_wfe.h"
  58. /** @addtogroup STM8L15x_StdPeriph_Driver
  59. * @{
  60. */
  61. /** @defgroup WFE
  62. * @brief WFE driver modules
  63. * @{
  64. */
  65. /* Private typedef -----------------------------------------------------------*/
  66. /* Private define ------------------------------------------------------------*/
  67. /* Private macro -------------------------------------------------------------*/
  68. /* Private function prototypes -----------------------------------------------*/
  69. /* Private functions ---------------------------------------------------------*/
  70. /** @defgroup WFE_Private_Functions
  71. * @{
  72. */
  73. /** @defgroup WFE_Group1 WFE Source configuration and management functions
  74. * @brief WFE Source configuration and management functions
  75. *
  76. @verbatim
  77. ===============================================================================
  78. WFE Source configuration and management functions
  79. ===============================================================================
  80. @endverbatim
  81. * @{
  82. */
  83. /**
  84. * @brief Deinitializes the WFE registers to their default reset value.
  85. * @param None
  86. * @retval None
  87. */
  88. void WFE_DeInit(void)
  89. {
  90. WFE->CR1 = WFE_CRX_RESET_VALUE;
  91. WFE->CR2 = WFE_CRX_RESET_VALUE;
  92. WFE->CR3 = WFE_CRX_RESET_VALUE;
  93. WFE->CR4 = WFE_CRX_RESET_VALUE;
  94. }
  95. /**
  96. * @brief Set the source that can generate the wake-up event.
  97. * @param WFE_Source: The wake-up event source .
  98. * This parameter can be one of the following values:
  99. * @arg WFE_Source_TIM2_EV0: TIM2 Update/Trigger and Break interrupt
  100. * @arg WFE_Source_TIM2_EV1: TIM2 Capture/Compare interrupt
  101. * @arg WFE_Source_TIM1_EV0: TIM1 Update/Trigger and Break interrupt
  102. * @arg WFE_Source_TIM1_EV1: TIM1 Capture/Compare interrupt
  103. * @arg WFE_Source_EXTI_EV0: I/O port interrupt from Pins 0
  104. * @arg WFE_Source_EXTI_EV1: I/O port interrupt from Pins 1
  105. * @arg WFE_Source_EXTI_EV2: I/O port interrupt from Pins 2
  106. * @arg WFE_Source_EXTI_EV3: I/O port interrupt from Pins 3
  107. * @arg WFE_Source_EXTI_EV4: I/O port interrupt from Pins 4
  108. * @arg WFE_Source_EXTI_EV5: I/O port interrupt from Pins 5
  109. * @arg WFE_Source_EXTI_EV6: I/O port interrupt from Pins 6
  110. * @arg WFE_Source_EXTI_EV7: I/O port interrupt from Pins 7
  111. * @arg WFE_Source_EXTI_EVB_G: I/O port interrupt from port B and G
  112. * @arg WFE_Source_EXTI_EVD_H: I/O port interrupt from Port D and H
  113. * @arg WFE_Source_EXTI_EVE_F: I/O port interrupt from Port E and F
  114. * @arg WFE_Source_ADC1_COMP_EV: ADC1, COMP1 and COMP2 interrupts
  115. * @arg WFE_Source_TIM3_EV0: TIM3 Update/Trigger and Break interrupt
  116. * @arg WFE_Source_TIM3_EV1: TIM3 Capture/Compare interrupt
  117. * @arg WFE_Source_TIM4_EV: TIM4 Update and Trigger interrupt
  118. * @arg WFE_Source_SPI1_EV: SPI1 Rx and Tx interrupt
  119. * @arg WFE_Source_I2C1_EV: I2C1 Rx and Tx interrupt
  120. * @arg WFE_Source_USART1_EV: USART1 Rx and Tx interrupt
  121. * @arg WFE_Source_DMA1CH01_EV: DMA1 channel 0 and 1 interrupt
  122. * @arg WFE_Source_DMA1CH23_EV: DMA1 channel 2 and 3 interrupt
  123. * @arg WFE_Source_RTC_CSS_EV: RTC or CSS on LSE event
  124. * @arg WFE_Source_SPI2_EV: SPI2 Rx and Tx interrupt
  125. * @arg WFE_Source_USART2_EV: USART2 Rx and Tx interrupt
  126. * @arg WFE_Source_USART3_EV: USART3 Rx and Tx interrupt
  127. * @arg WFE_Source_TIM5_EV0: TIM5 Update/Trigger and Break interrupt
  128. * @arg WFE_Source_TIM5_EV1: TIM5 Capture/Compare interrupt
  129. * @param NewState : The wake-up new state.
  130. * This parameter can be: ENABLE or DISABLE.
  131. * @retval None
  132. */
  133. void WFE_WakeUpSourceEventCmd(WFE_Source_TypeDef WFE_Source, FunctionalState NewState)
  134. {
  135. uint8_t register_index = 0;
  136. /* Check function parameters */
  137. assert_param(IS_WFE_SOURCE(WFE_Source));
  138. assert_param(IS_FUNCTIONAL_STATE(NewState));
  139. /* The mask is reversed in order to */
  140. register_index = (uint8_t)((uint16_t)WFE_Source >> 0x08);
  141. if (NewState != DISABLE)
  142. {
  143. switch (register_index)
  144. {
  145. case 1:
  146. WFE->CR1 |= (uint8_t)WFE_Source;
  147. break;
  148. case 2:
  149. WFE->CR2 |= (uint8_t)WFE_Source;
  150. break;
  151. case 3:
  152. WFE->CR3 |= (uint8_t)WFE_Source;
  153. break;
  154. case 4:
  155. WFE->CR4 |= (uint8_t)WFE_Source;
  156. break;
  157. default:
  158. break;
  159. }
  160. }
  161. else
  162. {
  163. switch (register_index)
  164. {
  165. case 1:
  166. WFE->CR1 &= (uint8_t)(~(uint8_t)WFE_Source);
  167. break;
  168. case 2:
  169. WFE->CR2 &= (uint8_t)(~ (uint8_t)WFE_Source);
  170. break;
  171. case 3:
  172. WFE->CR3 &= (uint8_t)(~(uint8_t)WFE_Source);
  173. break;
  174. case 4:
  175. WFE->CR4 &= (uint8_t)(~(uint8_t)WFE_Source);
  176. break;
  177. default:
  178. break;
  179. }
  180. }
  181. }
  182. /**
  183. * @brief Gets the status of the specified source event.
  184. * @param WFE_Source: The wake-up event source.
  185. * This parameter can be one of the following values:
  186. * @arg WFE_Source_TIM2_EV0: TIM2 Update/Trigger and Break interrupt
  187. * @arg WFE_Source_TIM2_EV1: TIM2 Capture/Compare interrupt
  188. * @arg WFE_Source_TIM1_EV0: TIM1 Update/Trigger and Break interrupt
  189. * @arg WFE_Source_TIM1_EV1: TIM1 Capture/Compare interrupt
  190. * @arg WFE_Source_EXTI_EV0: I/O port interrupt from Pins 0
  191. * @arg WFE_Source_EXTI_EV1: I/O port interrupt from Pins 1
  192. * @arg WFE_Source_EXTI_EV2: I/O port interrupt from Pins 2
  193. * @arg WFE_Source_EXTI_EV3: I/O port interrupt from Pins 3
  194. * @arg WFE_Source_EXTI_EV4: I/O port interrupt from Pins 4
  195. * @arg WFE_Source_EXTI_EV5: I/O port interrupt from Pins 5
  196. * @arg WFE_Source_EXTI_EV6: I/O port interrupt from Pins 6
  197. * @arg WFE_Source_EXTI_EV7: I/O port interrupt from Pins 7
  198. * @arg WFE_Source_EXTI_EVB_G: I/O port interrupt from port B and G
  199. * @arg WFE_Source_EXTI_EVD_H: I/O port interrupt from Port D and H
  200. * @arg WFE_Source_EXTI_EVE_F: I/O port interrupt from Port E and F
  201. * @arg WFE_Source_ADC1_COMP_EV: ADC1, COMP1 and COMP2 interrupts
  202. * @arg WFE_Source_TIM3_EV0: TIM3 Update/Trigger and Break interrupt
  203. * @arg WFE_Source_TIM3_EV1: TIM3 Capture/Compare interrupt
  204. * @arg WFE_Source_TIM4_EV: TIM4 Update and Trigger interrupt
  205. * @arg WFE_Source_SPI1_EV: SPI1 Rx and Tx interrupt
  206. * @arg WFE_Source_I2C1_EV: I2C1 Rx and Tx interrupt
  207. * @arg WFE_Source_USART1_EV: USART1 Rx and Tx interrupt
  208. * @arg WFE_Source_DMA1CH01_EV: DMA1 channel 0 and 1 interrupt
  209. * @arg WFE_Source_DMA1CH23_EV: DMA1 channel 2 and 3 interrupt
  210. * @arg WFE_Source_RTC_CSS_EV: RTC or CSS on LSE event
  211. * @arg WFE_Source_SPI2_EV: SPI2 Rx and Tx interrupt
  212. * @arg WFE_Source_USART2_EV: USART2 Rx and Tx interrupt
  213. * @arg WFE_Source_USART3_EV: USART3 Rx and Tx interrupt
  214. * @arg WFE_Source_TIM5_EV0: TIM5 Update/Trigger and Break interrupt
  215. * @arg WFE_Source_TIM5_EV1: TIM5 Capture/Compare interrupt
  216. * @retval Source Event state, ENABLE or DISABLE
  217. */
  218. FunctionalState WFE_GetWakeUpSourceEventStatus(WFE_Source_TypeDef WFE_Source)
  219. {
  220. FunctionalState status = DISABLE;
  221. /* Check function parameters */
  222. assert_param(IS_WFE_SOURCE(WFE_Source));
  223. switch (WFE_Source)
  224. {
  225. case WFE_Source_TIM2_EV0:
  226. case WFE_Source_TIM2_EV1:
  227. case WFE_Source_TIM1_EV0:
  228. case WFE_Source_TIM1_EV1:
  229. case WFE_Source_EXTI_EV0:
  230. case WFE_Source_EXTI_EV1:
  231. case WFE_Source_EXTI_EV2:
  232. case WFE_Source_EXTI_EV3:
  233. if ((WFE->CR1 & (uint8_t)WFE_Source) != (uint8_t)0x00)
  234. {
  235. /* The wake-up event source is enabled*/
  236. status = ENABLE;
  237. }
  238. else
  239. {
  240. /* The wake-up event source is disabled*/
  241. status = DISABLE;
  242. }
  243. break;
  244. case WFE_Source_EXTI_EV4:
  245. case WFE_Source_EXTI_EV5:
  246. case WFE_Source_EXTI_EV6:
  247. case WFE_Source_EXTI_EV7:
  248. case WFE_Source_EXTI_EVB_G:
  249. case WFE_Source_EXTI_EVD_H:
  250. case WFE_Source_EXTI_EVE_F:
  251. case WFE_Source_ADC1_COMP_EV:
  252. if ((WFE->CR2 & (uint8_t)WFE_Source) != (uint8_t)0x00)
  253. {
  254. /* The wake-up event source is enabled*/
  255. status = ENABLE;
  256. }
  257. else
  258. {
  259. /* The wake-up event source is disabled*/
  260. status = DISABLE;
  261. }
  262. break;
  263. case WFE_Source_TIM3_EV0:
  264. case WFE_Source_TIM3_EV1:
  265. case WFE_Source_TIM4_EV:
  266. case WFE_Source_SPI1_EV:
  267. case WFE_Source_I2C1_EV:
  268. case WFE_Source_USART1_EV:
  269. case WFE_Source_DMA1CH01_EV:
  270. case WFE_Source_DMA1CH23_EV:
  271. if ((WFE->CR3 & (uint8_t)WFE_Source) != (uint8_t)0x00)
  272. {
  273. /* The wake-up event source is enabled*/
  274. status = ENABLE;
  275. }
  276. else
  277. {
  278. /* The wake-up event source is disabled*/
  279. status = DISABLE;
  280. }
  281. break;
  282. case WFE_Source_TIM5_EV0:
  283. case WFE_Source_TIM5_EV1:
  284. case WFE_Source_AES_EV:
  285. case WFE_Source_SPI2_EV:
  286. case WFE_Source_USART2_EV:
  287. case WFE_Source_USART3_EV:
  288. case WFE_Source_RTC_CSS_EV:
  289. if ((WFE->CR4 & (uint8_t)WFE_Source) != (uint8_t)0x00)
  290. {
  291. /* The wake-up event source is enabled*/
  292. status = ENABLE;
  293. }
  294. else
  295. {
  296. /* The wake-up event source is disabled*/
  297. status = DISABLE;
  298. }
  299. break;
  300. default:
  301. break;
  302. }
  303. return status;
  304. }
  305. /**
  306. * @}
  307. */
  308. /**
  309. * @}
  310. */
  311. /**
  312. * @}
  313. */
  314. /**
  315. * @}
  316. */
  317. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/