STM8L15x Standard Peripherals Drivers: stm8l15x_wfe.c Source File

STM8L15x/16x Standard Peripherals Drivers

STM8L15x Standard Peripherals Drivers

stm8l15x_wfe.c

Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    stm8l15x_wfe.c
00004   * @author  MCD Application Team
00005   * @version V1.5.0
00006   * @date    13-May-2011
00007   * @brief   This file provides firmware functions to manage the following 
00008   *          functionalities of the Wait for Event (WFE) peripheral:           
00009   *           - WFE Source configuration and management
00010   *             
00011   *  @verbatim
00012   *               
00013   *          ===================================================================
00014   *                               WFE specific features
00015   *          ===================================================================
00016   *
00017   *           Wait for event mode (WFE) stops the CPU but allows the other peripherals
00018   *           and interrupt controller to continue running.
00019   *           This mode is entered from Run mode by executing a WFE instruction.
00020   *           Peripheral events can be generated by the timers, serial interfaces, 
00021   *           DMA controller, comparators and I/O ports. 
00022   *           These are enabled by using the WFE_WakeUpSourceEventCmd() function.
00023   *           
00024   *           When a peripheral event is enabled, the corresponding interrupts are 
00025   *           not served and you have to clear the corresponding flag status.
00026   *           
00027   *           There are two ways to wake up the CPU from WFE mode:
00028   *            - Interrupts: When an interrupt occurs, the CPU wakes up from WFE mode
00029   *              serves the interrupt then goes back to WFE mode.
00030   *            - Wake up event: when a wake up event occurs, the CPU wakes up and 
00031   *              resumes processing, in this case and to save time and power consumption
00032   *              there is no context save/restore activity.            
00033   *                          
00034   *
00035   *  @endverbatim
00036   *                 
00037   ******************************************************************************
00038   * @attention
00039   *
00040   * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
00041   * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
00042   * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
00043   * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
00044   * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
00045   * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
00046   *
00047   * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2>
00048   ******************************************************************************  
00049   */
00050 
00051 /* Includes ------------------------------------------------------------------*/
00052 #include "stm8l15x_wfe.h"
00053 
00054 /** @addtogroup STM8L15x_StdPeriph_Driver
00055   * @{
00056   */
00057   
00058 /** @defgroup WFE 
00059   * @brief WFE driver modules
00060   * @{
00061   */
00062    
00063 /* Private typedef -----------------------------------------------------------*/
00064 /* Private define ------------------------------------------------------------*/
00065 /* Private macro -------------------------------------------------------------*/
00066 /* Private function prototypes -----------------------------------------------*/
00067 /* Private functions ---------------------------------------------------------*/
00068 /** @defgroup WFE_Private_Functions
00069   * @{
00070   */
00071 
00072 /** @defgroup WFE_Group1 WFE Source configuration and management functions 
00073  *  @brief   WFE Source configuration and management functions  
00074  *
00075 @verbatim   
00076  ===============================================================================
00077                WFE Source configuration and management functions 
00078  ===============================================================================  
00079 
00080 @endverbatim
00081   * @{
00082   */
00083  
00084 /**
00085   * @brief  Deinitializes the WFE registers to their default reset value.
00086   * @param  None
00087   * @retval None
00088   */
00089 void WFE_DeInit(void)
00090 {
00091   WFE->CR1 = WFE_CRX_RESET_VALUE;
00092   WFE->CR2 = WFE_CRX_RESET_VALUE;
00093   WFE->CR3 = WFE_CRX_RESET_VALUE;
00094   WFE->CR4 = WFE_CRX_RESET_VALUE;
00095 }
00096 
00097 /**
00098   * @brief  Set the source that can generate the wake-up event.
00099   * @param  WFE_Source: The wake-up event source .
00100   *          This parameter can be one of the following values:
00101   *            @arg WFE_Source_TIM2_EV0: TIM2 Update/Trigger and Break interrupt  
00102   *            @arg WFE_Source_TIM2_EV1: TIM2 Capture/Compare interrupt 
00103   *            @arg WFE_Source_TIM1_EV0: TIM1 Update/Trigger and Break interrupt
00104   *            @arg WFE_Source_TIM1_EV1: TIM1 Capture/Compare interrupt 
00105   *            @arg WFE_Source_EXTI_EV0: I/O port interrupt from Pins 0
00106   *            @arg WFE_Source_EXTI_EV1: I/O port interrupt from Pins 1
00107   *            @arg WFE_Source_EXTI_EV2: I/O port interrupt from Pins 2
00108   *            @arg WFE_Source_EXTI_EV3: I/O port interrupt from Pins 3
00109   *            @arg WFE_Source_EXTI_EV4: I/O port interrupt from Pins 4
00110   *            @arg WFE_Source_EXTI_EV5: I/O port interrupt from Pins 5
00111   *            @arg WFE_Source_EXTI_EV6: I/O port interrupt from Pins 6
00112   *            @arg WFE_Source_EXTI_EV7: I/O port interrupt from Pins 7
00113   *            @arg WFE_Source_EXTI_EVB_G: I/O port interrupt from port B and G
00114   *            @arg WFE_Source_EXTI_EVD_H: I/O port interrupt from Port D and H
00115   *            @arg WFE_Source_EXTI_EVE_F: I/O port interrupt from Port E and F 
00116   *            @arg WFE_Source_ADC1_COMP_EV: ADC1, COMP1 and COMP2 interrupts
00117   *            @arg WFE_Source_TIM3_EV0: TIM3 Update/Trigger and Break interrupt
00118   *            @arg WFE_Source_TIM3_EV1: TIM3 Capture/Compare interrupt
00119   *            @arg WFE_Source_TIM4_EV: TIM4 Update and Trigger interrupt
00120   *            @arg WFE_Source_SPI1_EV: SPI1 Rx and Tx interrupt
00121   *            @arg WFE_Source_I2C1_EV: I2C1 Rx and Tx interrupt
00122   *            @arg WFE_Source_USART1_EV: USART1 Rx and Tx interrupt
00123   *            @arg WFE_Source_DMA1CH01_EV: DMA1 channel 0 and  1 interrupt
00124   *            @arg WFE_Source_DMA1CH23_EV: DMA1 channel 2 and  3  interrupt 
00125   *            @arg WFE_Source_RTC_CSS_EV: RTC or CSS on LSE event
00126   *            @arg WFE_Source_SPI2_EV: SPI2 Rx and Tx interrupt
00127   *            @arg WFE_Source_USART2_EV: USART2 Rx and Tx interrupt
00128   *            @arg WFE_Source_USART3_EV: USART3 Rx and Tx interrupt
00129   *            @arg WFE_Source_TIM5_EV0: TIM5 Update/Trigger and Break interrupt
00130   *            @arg WFE_Source_TIM5_EV1: TIM5 Capture/Compare interrupt                                                        
00131   * @param  NewState : The wake-up new state.
00132   *          This parameter can be: ENABLE or DISABLE.
00133   * @retval None
00134   */
00135 void WFE_WakeUpSourceEventCmd(WFE_Source_TypeDef WFE_Source, FunctionalState NewState)
00136 {
00137   uint8_t register_index = 0;
00138   /* Check function parameters */
00139   assert_param(IS_WFE_SOURCE(WFE_Source));
00140   assert_param(IS_FUNCTIONAL_STATE(NewState));
00141 
00142   /* The mask is reversed in order to  */
00143   register_index = (uint8_t)((uint16_t)WFE_Source >> 0x08);
00144 
00145   if (NewState != DISABLE)
00146   {
00147     switch (register_index)
00148     {
00149       case 1:
00150         WFE->CR1 |= (uint8_t)WFE_Source;
00151         break;
00152 
00153       case 2:
00154         WFE->CR2 |= (uint8_t)WFE_Source;
00155         break;
00156 
00157       case 3:
00158         WFE->CR3 |= (uint8_t)WFE_Source;
00159         break;
00160 
00161       case 4:
00162         WFE->CR4 |= (uint8_t)WFE_Source;
00163         break;
00164 
00165       default:
00166         break;
00167     }
00168   }
00169   else
00170   {
00171     switch (register_index)
00172     {
00173       case 1:
00174         WFE->CR1 &= (uint8_t)(~(uint8_t)WFE_Source);
00175         break;
00176 
00177       case 2:
00178         WFE->CR2 &= (uint8_t)(~ (uint8_t)WFE_Source);
00179         break;
00180 
00181       case 3:
00182         WFE->CR3 &= (uint8_t)(~(uint8_t)WFE_Source);
00183         break;
00184 
00185       case 4:
00186         WFE->CR4 &= (uint8_t)(~(uint8_t)WFE_Source);
00187         break;
00188 
00189       default:
00190         break;
00191     }
00192   }
00193 }
00194 
00195 /**
00196   * @brief  Gets the status of the specified source event.
00197   * @param  WFE_Source: The wake-up event source.
00198   *          This parameter can be one of the following values:
00199   *            @arg WFE_Source_TIM2_EV0: TIM2 Update/Trigger and Break interrupt  
00200   *            @arg WFE_Source_TIM2_EV1: TIM2 Capture/Compare interrupt 
00201   *            @arg WFE_Source_TIM1_EV0: TIM1 Update/Trigger and Break interrupt
00202   *            @arg WFE_Source_TIM1_EV1: TIM1 Capture/Compare interrupt 
00203   *            @arg WFE_Source_EXTI_EV0: I/O port interrupt from Pins 0
00204   *            @arg WFE_Source_EXTI_EV1: I/O port interrupt from Pins 1
00205   *            @arg WFE_Source_EXTI_EV2: I/O port interrupt from Pins 2
00206   *            @arg WFE_Source_EXTI_EV3: I/O port interrupt from Pins 3
00207   *            @arg WFE_Source_EXTI_EV4: I/O port interrupt from Pins 4
00208   *            @arg WFE_Source_EXTI_EV5: I/O port interrupt from Pins 5
00209   *            @arg WFE_Source_EXTI_EV6: I/O port interrupt from Pins 6
00210   *            @arg WFE_Source_EXTI_EV7: I/O port interrupt from Pins 7
00211   *            @arg WFE_Source_EXTI_EVB_G: I/O port interrupt from port B and G
00212   *            @arg WFE_Source_EXTI_EVD_H: I/O port interrupt from Port D and H
00213   *            @arg WFE_Source_EXTI_EVE_F: I/O port interrupt from Port E and F 
00214   *            @arg WFE_Source_ADC1_COMP_EV: ADC1, COMP1 and COMP2 interrupts
00215   *            @arg WFE_Source_TIM3_EV0: TIM3 Update/Trigger and Break interrupt
00216   *            @arg WFE_Source_TIM3_EV1: TIM3 Capture/Compare interrupt
00217   *            @arg WFE_Source_TIM4_EV: TIM4 Update and Trigger interrupt
00218   *            @arg WFE_Source_SPI1_EV: SPI1 Rx and Tx interrupt
00219   *            @arg WFE_Source_I2C1_EV: I2C1 Rx and Tx interrupt
00220   *            @arg WFE_Source_USART1_EV: USART1 Rx and Tx interrupt
00221   *            @arg WFE_Source_DMA1CH01_EV: DMA1 channel 0 and  1 interrupt
00222   *            @arg WFE_Source_DMA1CH23_EV: DMA1 channel 2 and  3  interrupt 
00223   *            @arg WFE_Source_RTC_CSS_EV: RTC or CSS on LSE event
00224   *            @arg WFE_Source_SPI2_EV: SPI2 Rx and Tx interrupt
00225   *            @arg WFE_Source_USART2_EV: USART2 Rx and Tx interrupt
00226   *            @arg WFE_Source_USART3_EV: USART3 Rx and Tx interrupt
00227   *            @arg WFE_Source_TIM5_EV0: TIM5 Update/Trigger and Break interrupt
00228   *            @arg WFE_Source_TIM5_EV1: TIM5 Capture/Compare interrupt  
00229   * @retval Source Event state, ENABLE or DISABLE
00230   */
00231 FunctionalState WFE_GetWakeUpSourceEventStatus(WFE_Source_TypeDef WFE_Source)
00232 {
00233   FunctionalState status = DISABLE;
00234   /* Check function parameters */
00235   assert_param(IS_WFE_SOURCE(WFE_Source));
00236 
00237   switch (WFE_Source)
00238   {
00239     case WFE_Source_TIM2_EV0:
00240     case WFE_Source_TIM2_EV1:
00241     case WFE_Source_TIM1_EV0:
00242     case WFE_Source_TIM1_EV1:
00243     case WFE_Source_EXTI_EV0:
00244     case WFE_Source_EXTI_EV1:
00245     case WFE_Source_EXTI_EV2:
00246     case WFE_Source_EXTI_EV3:
00247 
00248       if ((WFE->CR1 & (uint8_t)WFE_Source) != (uint8_t)0x00)
00249       {
00250         /* The wake-up event source is enabled*/
00251         status = ENABLE;
00252       }
00253       else
00254       {
00255         /* The wake-up event source is disabled*/
00256         status = DISABLE;
00257       }
00258       break;
00259 
00260     case WFE_Source_EXTI_EV4:
00261     case WFE_Source_EXTI_EV5:
00262     case WFE_Source_EXTI_EV6:
00263     case WFE_Source_EXTI_EV7:
00264     case WFE_Source_EXTI_EVB_G:
00265     case WFE_Source_EXTI_EVD_H:
00266     case WFE_Source_EXTI_EVE_F:
00267     case WFE_Source_ADC1_COMP_EV:
00268 
00269       if ((WFE->CR2 & (uint8_t)WFE_Source) != (uint8_t)0x00)
00270       {
00271         /* The wake-up event source is enabled*/
00272         status = ENABLE;
00273       }
00274       else
00275       {
00276         /* The wake-up event source is disabled*/
00277         status = DISABLE;
00278       }
00279       break;
00280     case WFE_Source_TIM3_EV0:
00281     case WFE_Source_TIM3_EV1:
00282     case WFE_Source_TIM4_EV:
00283     case WFE_Source_SPI1_EV:
00284     case WFE_Source_I2C1_EV:
00285     case WFE_Source_USART1_EV:
00286     case WFE_Source_DMA1CH01_EV:
00287     case WFE_Source_DMA1CH23_EV:
00288 
00289       if ((WFE->CR3 & (uint8_t)WFE_Source) != (uint8_t)0x00)
00290       {
00291         /* The wake-up event source is enabled*/
00292         status = ENABLE;
00293       }
00294       else
00295       {
00296         /* The wake-up event source is disabled*/
00297         status = DISABLE;
00298       }
00299       break;
00300 
00301     case WFE_Source_TIM5_EV0:
00302     case WFE_Source_TIM5_EV1:
00303     case WFE_Source_AES_EV:
00304     case WFE_Source_SPI2_EV:
00305     case WFE_Source_USART2_EV:
00306     case WFE_Source_USART3_EV:
00307     case WFE_Source_RTC_CSS_EV:
00308 
00309       if ((WFE->CR4 & (uint8_t)WFE_Source) != (uint8_t)0x00)
00310       {
00311         /* The wake-up event source is enabled*/
00312         status = ENABLE;
00313       }
00314       else
00315       {
00316         /* The wake-up event source is disabled*/
00317         status = DISABLE;
00318       }
00319       break;
00320     default:
00321       break;
00322   }
00323   return status;
00324 }
00325 
00326 /**
00327   * @}
00328   */
00329 
00330 /**
00331   * @}
00332   */
00333   
00334 /**
00335   * @}
00336   */
00337 
00338 /**
00339   * @}
00340   */
00341 
00342 /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
STM8S Firmware Library: Overview

 

 

 

For complete documentation on STM8L15x 8-bit microcontrollers platform visit www.st.com