TUKS MCU Introductory course / TUKS-COURSE-THERMOMETER

Fork of TUKS-COURSE-TIMER by TUKS MCU Introductory course

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers stm32l4xx_hal_lptim.c Source File

stm32l4xx_hal_lptim.c

Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    stm32l4xx_hal_lptim.c
00004   * @author  MCD Application Team
00005   * @version V1.5.1
00006   * @date    31-May-2016
00007   * @brief   LPTIM HAL module driver. 
00008   *          This file provides firmware functions to manage the following 
00009   *          functionalities of the Low Power Timer (LPTIM) peripheral:
00010   *           + Initialization and de-initialization functions.
00011   *           + Start/Stop operation functions in polling mode.
00012   *           + Start/Stop operation functions in interrupt mode.
00013   *           + Reading operation functions.
00014   *           + Peripheral State functions.
00015   *         
00016   @verbatim
00017   ==============================================================================
00018                      ##### How to use this driver #####
00019   ==============================================================================
00020     [..]
00021       The LPTIM HAL driver can be used as follows:
00022 
00023       (#)Initialize the LPTIM low level resources by implementing the
00024         HAL_LPTIM_MspInit():
00025          (++) Enable the LPTIM interface clock using __HAL_RCC_LPTIMx_CLK_ENABLE().
00026          (++) In case of using interrupts (e.g. HAL_LPTIM_PWM_Start_IT()):
00027              (+++) Configure the LPTIM interrupt priority using HAL_NVIC_SetPriority().
00028              (+++) Enable the LPTIM IRQ handler using HAL_NVIC_EnableIRQ().
00029              (+++) In LPTIM IRQ handler, call HAL_LPTIM_IRQHandler().
00030     
00031       (#)Initialize the LPTIM HAL using HAL_LPTIM_Init(). This function
00032          configures mainly:
00033          (++) The instance: LPTIM1 or LPTIM2.
00034          (++) Clock: the counter clock.
00035              (+++) Source   : it can be either the ULPTIM input (IN1) or one of
00036                               the internal clock; (APB, LSE, LSI or MSI).
00037              (+++) Prescaler: select the clock divider.
00038          (++)  UltraLowPowerClock : To be used only if the ULPTIM is selected
00039                as counter clock source.
00040              (+++) Polarity:   polarity of the active edge for the counter unit
00041                                if the ULPTIM input is selected.
00042              (+++) SampleTime: clock sampling time to configure the clock glitch
00043                                filter.              
00044          (++) Trigger: How the counter start.
00045              (+++) Source: trigger can be software or one of the hardware triggers.
00046              (+++) ActiveEdge : only for hardware trigger.
00047              (+++) SampleTime : trigger sampling time to configure the trigger
00048                                 glitch filter.
00049          (++) OutputPolarity : 2 opposite polarities are possible.
00050          (++) UpdateMode: specifies whether the update of the autoreload and
00051               the compare values is done immediately or after the end of current
00052               period.   
00053          (++) Input1Source: Source selected for input1 (GPIO or comparator output).
00054          (++) Input2Source: Source selected for input2 (GPIO or comparator output). 
00055               Input2 is used only for encoder feature so is used only for LPTIM1 instance.
00056     
00057       (#)Six modes are available:
00058       
00059          (++) PWM Mode: To generate a PWM signal with specified period and pulse,
00060          call HAL_LPTIM_PWM_Start() or HAL_LPTIM_PWM_Start_IT() for interruption
00061          mode.
00062          
00063          (++) One Pulse Mode: To generate pulse with specified width in response
00064          to a stimulus, call HAL_LPTIM_OnePulse_Start() or
00065          HAL_LPTIM_OnePulse_Start_IT() for interruption mode.
00066          
00067          (++) Set once Mode: In this mode, the output changes the level (from
00068          low level to high level if the output polarity is configured high, else
00069          the opposite) when a compare match occurs. To start this mode, call 
00070          HAL_LPTIM_SetOnce_Start() or HAL_LPTIM_SetOnce_Start_IT() for
00071          interruption mode.
00072          
00073          (++) Encoder Mode: To use the encoder interface call
00074          HAL_LPTIM_Encoder_Start() or HAL_LPTIM_Encoder_Start_IT() for 
00075          interruption mode. Only available for LPTIM1 instance.
00076          
00077          (++) Time out Mode: an active edge on one selected trigger input rests
00078          the counter. The first trigger event will start the timer, any
00079          successive trigger event will reset the counter and the timer will
00080          restart. To start this mode call HAL_LPTIM_TimeOut_Start_IT() or 
00081          HAL_LPTIM_TimeOut_Start_IT() for interruption mode.
00082          
00083          (++) Counter Mode: counter can be used to count external events on
00084          the LPTIM Input1 or it can be used to count internal clock cycles.
00085          To start this mode, call HAL_LPTIM_Counter_Start() or 
00086          HAL_LPTIM_Counter_Start_IT() for interruption mode.             
00087 
00088     
00089       (#) User can stop any process by calling the corresponding API:
00090           HAL_LPTIM_Xxx_Stop() or HAL_LPTIM_Xxx_Stop_IT() if the process is
00091           already started in interruption mode.
00092          
00093       (#) De-initialize the LPTIM peripheral using HAL_LPTIM_DeInit().
00094 
00095   @endverbatim
00096   ******************************************************************************
00097   * @attention
00098   *
00099   * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
00100   *
00101   * Redistribution and use in source and binary forms, with or without modification,
00102   * are permitted provided that the following conditions are met:
00103   *   1. Redistributions of source code must retain the above copyright notice,
00104   *      this list of conditions and the following disclaimer.
00105   *   2. Redistributions in binary form must reproduce the above copyright notice,
00106   *      this list of conditions and the following disclaimer in the documentation
00107   *      and/or other materials provided with the distribution.
00108   *   3. Neither the name of STMicroelectronics nor the names of its contributors
00109   *      may be used to endorse or promote products derived from this software
00110   *      without specific prior written permission.
00111   *
00112   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00113   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00114   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00115   * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
00116   * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00117   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00118   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00119   * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00120   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00121   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00122   *
00123   ******************************************************************************  
00124   */ 
00125 
00126 /* Includes ------------------------------------------------------------------*/
00127 #include "stm32l4xx_hal.h"
00128 
00129 /** @addtogroup STM32L4xx_HAL_Driver
00130   * @{
00131   */
00132 
00133 /** @defgroup LPTIM LPTIM
00134   * @brief LPTIM HAL module driver.
00135   * @{
00136   */
00137 
00138 #ifdef HAL_LPTIM_MODULE_ENABLED
00139 /* Private typedef -----------------------------------------------------------*/
00140 /* Private define ------------------------------------------------------------*/
00141 /* Private macro -------------------------------------------------------------*/
00142 /* Private variables ---------------------------------------------------------*/
00143 /* Private function prototypes -----------------------------------------------*/
00144 /* Exported functions --------------------------------------------------------*/
00145 
00146 /** @defgroup LPTIM_Exported_Functions LPTIM Exported Functions
00147   * @{
00148   */
00149 
00150 /** @defgroup LPTIM_Exported_Functions_Group1 Initialization/de-initialization functions 
00151  *  @brief    Initialization and Configuration functions. 
00152  *
00153 @verbatim    
00154   ==============================================================================
00155               ##### Initialization and de-initialization functions #####
00156   ==============================================================================
00157     [..]  This section provides functions allowing to:
00158       (+) Initialize the LPTIM according to the specified parameters in the
00159           LPTIM_InitTypeDef and initialize the associated handle.
00160       (+) DeInitialize the LPTIM peripheral.
00161       (+) Initialize the LPTIM MSP.
00162       (+) DeInitialize the LPTIM MSP. 
00163  
00164 @endverbatim
00165   * @{
00166   */
00167 
00168 /**
00169   * @brief  Initialize the LPTIM according to the specified parameters in the
00170   *         LPTIM_InitTypeDef and initialize the associated handle.
00171   * @param  hlptim: LPTIM handle
00172   * @retval HAL status
00173   */
00174 HAL_StatusTypeDef HAL_LPTIM_Init(LPTIM_HandleTypeDef *hlptim)
00175 {
00176   uint32_t tmpcfgr = 0;
00177 
00178   /* Check the LPTIM handle allocation */
00179   if(hlptim == NULL)
00180   {
00181     return HAL_ERROR;
00182   }
00183 
00184   /* Check the parameters */
00185   assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
00186   
00187   assert_param(IS_LPTIM_CLOCK_SOURCE(hlptim->Init.Clock.Source));
00188   assert_param(IS_LPTIM_CLOCK_PRESCALER(hlptim->Init.Clock.Prescaler));  
00189   if ((hlptim->Init.Clock.Source) ==  LPTIM_CLOCKSOURCE_ULPTIM)
00190   {
00191     assert_param(IS_LPTIM_CLOCK_POLARITY(hlptim->Init.UltraLowPowerClock.Polarity));
00192     assert_param(IS_LPTIM_CLOCK_SAMPLE_TIME(hlptim->Init.UltraLowPowerClock.SampleTime));
00193   }  
00194   assert_param(IS_LPTIM_TRG_SOURCE(hlptim->Init.Trigger.Source));
00195   if ((hlptim->Init.Trigger.Source) !=  LPTIM_TRIGSOURCE_SOFTWARE)
00196   {
00197     assert_param(IS_LPTIM_TRIG_SAMPLE_TIME(hlptim->Init.Trigger.SampleTime));
00198     assert_param(IS_LPTIM_EXT_TRG_POLARITY(hlptim->Init.Trigger.ActiveEdge));
00199   }  
00200   assert_param(IS_LPTIM_OUTPUT_POLARITY(hlptim->Init.OutputPolarity));  
00201   assert_param(IS_LPTIM_UPDATE_MODE(hlptim->Init.UpdateMode));
00202   assert_param(IS_LPTIM_COUNTER_SOURCE(hlptim->Init.CounterSource));
00203   
00204   if(hlptim->State == HAL_LPTIM_STATE_RESET)
00205   {
00206     /* Allocate lock resource and initialize it */
00207     hlptim->Lock = HAL_UNLOCKED;
00208 
00209     /* Init the low level hardware */
00210     HAL_LPTIM_MspInit(hlptim);
00211   }
00212   
00213   /* Change the LPTIM state */
00214   hlptim->State = HAL_LPTIM_STATE_BUSY;
00215   
00216   /* Get the LPTIMx CFGR value */
00217   tmpcfgr = hlptim->Instance->CFGR;
00218   
00219   if ((hlptim->Init.Clock.Source) ==  LPTIM_CLOCKSOURCE_ULPTIM)
00220   {
00221     tmpcfgr &= (uint32_t)(~(LPTIM_CFGR_CKPOL | LPTIM_CFGR_CKFLT));
00222   }
00223   if ((hlptim->Init.Trigger.Source) !=  LPTIM_TRIGSOURCE_SOFTWARE)
00224   {
00225     tmpcfgr &= (uint32_t)(~ (LPTIM_CFGR_TRGFLT | LPTIM_CFGR_TRIGSEL));
00226   }
00227     
00228   /* Clear CKSEL, PRESC, TRIGEN, TRGFLT, WAVPOL, PRELOAD & COUNTMODE bits */
00229   tmpcfgr &= (uint32_t)(~(LPTIM_CFGR_CKSEL | LPTIM_CFGR_TRIGEN | LPTIM_CFGR_PRELOAD |
00230                           LPTIM_CFGR_WAVPOL | LPTIM_CFGR_PRESC | LPTIM_CFGR_COUNTMODE ));
00231   
00232   /* Set initialization parameters */
00233   tmpcfgr |= (hlptim->Init.Clock.Source    |
00234               hlptim->Init.Clock.Prescaler |
00235               hlptim->Init.OutputPolarity  |
00236               hlptim->Init.UpdateMode      |
00237               hlptim->Init.CounterSource);
00238   
00239   if ((hlptim->Init.Clock.Source) ==  LPTIM_CLOCKSOURCE_ULPTIM)
00240   {
00241     tmpcfgr |=  (hlptim->Init.UltraLowPowerClock.Polarity |
00242                 hlptim->Init.UltraLowPowerClock.SampleTime);
00243   } 
00244   
00245   if ((hlptim->Init.Trigger.Source) !=  LPTIM_TRIGSOURCE_SOFTWARE)
00246   {
00247     /* Enable External trigger and set the trigger source */
00248     tmpcfgr |= (hlptim->Init.Trigger.Source     |
00249                 hlptim->Init.Trigger.ActiveEdge |
00250                 hlptim->Init.Trigger.SampleTime);
00251   }
00252   
00253   /* Write to LPTIMx CFGR */
00254   hlptim->Instance->CFGR = tmpcfgr;
00255 
00256   /* Configure LPTIM input sources */
00257   if(hlptim->Instance == LPTIM1)
00258   {
00259     /* Check LPTIM1 Input1 and Input2 sources */
00260     assert_param(IS_LPTIM_INPUT1_SOURCE(hlptim->Instance,hlptim->Init.Input1Source));
00261     assert_param(IS_LPTIM_INPUT2_SOURCE(hlptim->Instance,hlptim->Init.Input2Source));
00262     
00263     /* Configure LPTIM1 Input1 and Input2 sources */
00264     hlptim->Instance->OR = (hlptim->Init.Input1Source | hlptim->Init.Input2Source);
00265   }
00266   else
00267   {
00268     /* Check LPTIM2 Input1 source */
00269     assert_param(IS_LPTIM_INPUT1_SOURCE(hlptim->Instance,hlptim->Init.Input1Source));
00270     
00271     /* Configure LPTIM2 Input1 source */
00272     hlptim->Instance->OR = hlptim->Init.Input1Source;
00273   }
00274   
00275   /* Change the LPTIM state */
00276   hlptim->State = HAL_LPTIM_STATE_READY;
00277   
00278   /* Return function status */
00279   return HAL_OK;
00280 }
00281 
00282 /**
00283   * @brief  DeInitialize the LPTIM peripheral. 
00284   * @param  hlptim: LPTIM handle
00285   * @retval HAL status
00286   */
00287 HAL_StatusTypeDef HAL_LPTIM_DeInit(LPTIM_HandleTypeDef *hlptim)
00288 {
00289   /* Check the LPTIM handle allocation */
00290   if(hlptim == NULL)
00291   {
00292     return HAL_ERROR;
00293   }
00294   
00295   /* Change the LPTIM state */
00296   hlptim->State = HAL_LPTIM_STATE_BUSY;
00297   
00298   /* Disable the LPTIM Peripheral Clock */
00299   __HAL_LPTIM_DISABLE(hlptim);
00300   
00301   /* DeInit the low level hardware: CLOCK, NVIC.*/
00302   HAL_LPTIM_MspDeInit(hlptim);
00303   
00304   /* Change the LPTIM state */
00305   hlptim->State = HAL_LPTIM_STATE_RESET;
00306   
00307   /* Release Lock */
00308   __HAL_UNLOCK(hlptim);
00309   
00310   /* Return function status */
00311   return HAL_OK;
00312 }
00313 
00314 /**
00315   * @brief  Initialize the LPTIM MSP.
00316   * @param  hlptim: LPTIM handle
00317   * @retval None
00318   */
00319 __weak void HAL_LPTIM_MspInit(LPTIM_HandleTypeDef *hlptim)
00320 {
00321   /* Prevent unused argument(s) compilation warning */
00322   UNUSED(hlptim);
00323 
00324   /* NOTE : This function should not be modified, when the callback is needed,
00325             the HAL_LPTIM_MspInit could be implemented in the user file
00326    */
00327 }
00328 
00329 /**
00330   * @brief  DeInitialize LPTIM MSP.
00331   * @param  hlptim: LPTIM handle
00332   * @retval None
00333   */
00334 __weak void HAL_LPTIM_MspDeInit(LPTIM_HandleTypeDef *hlptim)
00335 {
00336   /* Prevent unused argument(s) compilation warning */
00337   UNUSED(hlptim);
00338 
00339   /* NOTE : This function should not be modified, when the callback is needed,
00340             the HAL_LPTIM_MspDeInit could be implemented in the user file
00341    */
00342 }
00343 
00344 /**
00345   * @}
00346   */
00347 
00348 /** @defgroup LPTIM_Exported_Functions_Group2 LPTIM Start-Stop operation functions 
00349  *  @brief   Start-Stop operation functions. 
00350  *
00351 @verbatim   
00352   ==============================================================================
00353                 ##### LPTIM Start Stop operation functions #####
00354   ==============================================================================  
00355     [..]  This section provides functions allowing to:
00356       (+) Start the PWM mode.
00357       (+) Stop the PWM mode.
00358       (+) Start the One pulse mode.
00359       (+) Stop the One pulse mode.
00360       (+) Start the Set once mode.
00361       (+) Stop the Set once mode.
00362       (+) Start the Encoder mode.
00363       (+) Stop the Encoder mode.
00364       (+) Start the Timeout mode.
00365       (+) Stop the Timeout mode.      
00366       (+) Start the Counter mode.
00367       (+) Stop the Counter mode.
00368       
00369 
00370 @endverbatim
00371   * @{
00372   */
00373     
00374 /**
00375   * @brief  Start the LPTIM PWM generation.
00376   * @param  hlptim : LPTIM handle
00377   * @param  Period : Specifies the Autoreload value.
00378   *         This parameter must be a value between 0x0000 and 0xFFFF.
00379   * @param  Pulse : Specifies the compare value.
00380   *         This parameter must be a value between 0x0000 and 0xFFFF.
00381   * @retval HAL status
00382   */
00383 HAL_StatusTypeDef HAL_LPTIM_PWM_Start(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Pulse)
00384 {
00385   /* Check the parameters */
00386   assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
00387   assert_param(IS_LPTIM_PERIOD(Period));
00388   assert_param(IS_LPTIM_PULSE(Pulse));
00389                
00390   /* Set the LPTIM state */
00391   hlptim->State= HAL_LPTIM_STATE_BUSY;
00392  
00393   /* Reset WAVE bit to set PWM mode */
00394   hlptim->Instance->CFGR &= ~LPTIM_CFGR_WAVE;
00395   
00396   /* Enable the Peripheral */
00397   __HAL_LPTIM_ENABLE(hlptim);
00398   
00399   /* Load the period value in the autoreload register */
00400   __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
00401   
00402   /* Load the pulse value in the compare register */
00403   __HAL_LPTIM_COMPARE_SET(hlptim, Pulse);
00404   
00405   /* Start timer in continuous mode */
00406   __HAL_LPTIM_START_CONTINUOUS(hlptim);
00407     
00408   /* Change the TIM state*/
00409   hlptim->State= HAL_LPTIM_STATE_READY;
00410   
00411   /* Return function status */
00412   return HAL_OK;
00413 }
00414 
00415 /**
00416   * @brief  Stop the LPTIM PWM generation.
00417   * @param  hlptim : LPTIM handle
00418   * @retval HAL status
00419   */
00420 HAL_StatusTypeDef HAL_LPTIM_PWM_Stop(LPTIM_HandleTypeDef *hlptim)
00421 {
00422   /* Check the parameters */
00423   assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
00424                
00425   /* Set the LPTIM state */
00426   hlptim->State= HAL_LPTIM_STATE_BUSY;
00427   
00428   /* Disable the Peripheral */
00429   __HAL_LPTIM_DISABLE(hlptim);
00430 
00431   /* Change the TIM state*/
00432   hlptim->State= HAL_LPTIM_STATE_READY;
00433   
00434   /* Return function status */
00435   return HAL_OK;
00436 }
00437 
00438 /**
00439   * @brief  Start the LPTIM PWM generation in interrupt mode.
00440   * @param  hlptim : LPTIM handle
00441   * @param  Period : Specifies the Autoreload value.
00442   *         This parameter must be a value between 0x0000 and 0xFFFF
00443   * @param  Pulse : Specifies the compare value.
00444   *         This parameter must be a value between 0x0000 and 0xFFFF
00445   * @retval HAL status
00446   */
00447 HAL_StatusTypeDef HAL_LPTIM_PWM_Start_IT(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Pulse)
00448 {
00449   /* Check the parameters */
00450   assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
00451   assert_param(IS_LPTIM_PERIOD(Period));
00452   assert_param(IS_LPTIM_PULSE(Pulse));
00453                
00454   /* Set the LPTIM state */
00455   hlptim->State= HAL_LPTIM_STATE_BUSY;
00456  
00457   /* Reset WAVE bit to set PWM mode */
00458   hlptim->Instance->CFGR &= ~LPTIM_CFGR_WAVE;
00459   
00460   /* Enable Autoreload write complete interrupt */
00461   __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_ARROK);
00462   
00463   /* Enable Compare write complete interrupt */
00464   __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_CMPOK);
00465   
00466   /* Enable Autoreload match interrupt */
00467   __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_ARRM);
00468   
00469   /* Enable Compare match interrupt */
00470   __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_CMPM);
00471   
00472   /* If external trigger source is used, then enable external trigger interrupt */
00473   if ((hlptim->Init.Trigger.Source) !=  LPTIM_TRIGSOURCE_SOFTWARE)
00474   {
00475     /* Enable external trigger interrupt */
00476     __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_EXTTRIG);
00477   }  
00478   
00479   /* Enable the Peripheral */
00480   __HAL_LPTIM_ENABLE(hlptim);
00481   
00482   /* Load the period value in the autoreload register */
00483   __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
00484   
00485   /* Load the pulse value in the compare register */
00486   __HAL_LPTIM_COMPARE_SET(hlptim, Pulse);
00487   
00488   /* Start timer in continuous mode */
00489   __HAL_LPTIM_START_CONTINUOUS(hlptim);
00490     
00491   /* Change the TIM state*/
00492   hlptim->State= HAL_LPTIM_STATE_READY;
00493   
00494   /* Return function status */
00495   return HAL_OK;
00496 }
00497 
00498 /**
00499   * @brief  Stop the LPTIM PWM generation in interrupt mode.
00500   * @param  hlptim : LPTIM handle
00501   * @retval HAL status
00502   */
00503 HAL_StatusTypeDef HAL_LPTIM_PWM_Stop_IT(LPTIM_HandleTypeDef *hlptim)
00504 {
00505   /* Check the parameters */
00506   assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
00507                
00508   /* Set the LPTIM state */
00509   hlptim->State= HAL_LPTIM_STATE_BUSY;
00510   
00511   /* Disable the Peripheral */
00512   __HAL_LPTIM_DISABLE(hlptim);
00513   
00514     /* Disable Autoreload write complete interrupt */
00515   __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_ARROK);
00516   
00517   /* Disable Compare write complete interrupt */
00518   __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_CMPOK);
00519   
00520   /* Disable Autoreload match interrupt */
00521   __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_ARRM);
00522   
00523   /* Disable Compare match interrupt */
00524   __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_CMPM);
00525   
00526   /* If external trigger source is used, then disable external trigger interrupt */
00527   if ((hlptim->Init.Trigger.Source) !=  LPTIM_TRIGSOURCE_SOFTWARE)
00528   {
00529     /* Disable external trigger interrupt */
00530     __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_EXTTRIG);
00531   }  
00532 
00533   /* Change the TIM state*/
00534   hlptim->State= HAL_LPTIM_STATE_READY;
00535   
00536   /* Return function status */
00537   return HAL_OK;
00538 }
00539 
00540 /**
00541   * @brief  Start the LPTIM One pulse generation.
00542   * @param  hlptim : LPTIM handle
00543   * @param  Period : Specifies the Autoreload value.
00544   *         This parameter must be a value between 0x0000 and 0xFFFF.
00545   * @param  Pulse : Specifies the compare value.
00546   *         This parameter must be a value between 0x0000 and 0xFFFF.
00547   * @retval HAL status
00548   */
00549 HAL_StatusTypeDef HAL_LPTIM_OnePulse_Start(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Pulse)
00550 {
00551   /* Check the parameters */
00552   assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
00553   assert_param(IS_LPTIM_PERIOD(Period));
00554   assert_param(IS_LPTIM_PULSE(Pulse));
00555                
00556   /* Set the LPTIM state */
00557   hlptim->State= HAL_LPTIM_STATE_BUSY;
00558   
00559   /* Reset WAVE bit to set one pulse mode */
00560   hlptim->Instance->CFGR &= ~LPTIM_CFGR_WAVE;
00561   
00562   /* Enable the Peripheral */
00563   __HAL_LPTIM_ENABLE(hlptim);
00564   
00565   /* Load the period value in the autoreload register */
00566   __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
00567   
00568   /* Load the pulse value in the compare register */
00569   __HAL_LPTIM_COMPARE_SET(hlptim, Pulse);
00570   
00571   /* Start timer in continuous mode */
00572   __HAL_LPTIM_START_SINGLE(hlptim);
00573     
00574   /* Change the TIM state*/
00575   hlptim->State= HAL_LPTIM_STATE_READY;
00576   
00577   /* Return function status */
00578   return HAL_OK;
00579 }
00580 
00581 /**
00582   * @brief  Stop the LPTIM One pulse generation.
00583   * @param  hlptim : LPTIM handle
00584   * @retval HAL status
00585   */
00586 HAL_StatusTypeDef HAL_LPTIM_OnePulse_Stop(LPTIM_HandleTypeDef *hlptim)
00587 {
00588   /* Check the parameters */
00589   assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
00590                
00591   /* Set the LPTIM state */
00592   hlptim->State= HAL_LPTIM_STATE_BUSY;
00593   
00594   /* Disable the Peripheral */
00595   __HAL_LPTIM_DISABLE(hlptim);
00596 
00597   /* Change the TIM state*/
00598   hlptim->State= HAL_LPTIM_STATE_READY;
00599   
00600   /* Return function status */
00601   return HAL_OK;
00602 }
00603 
00604 /**
00605   * @brief  Start the LPTIM One pulse generation in interrupt mode.
00606   * @param  hlptim : LPTIM handle
00607   * @param  Period : Specifies the Autoreload value.
00608   *         This parameter must be a value between 0x0000 and 0xFFFF.
00609   * @param  Pulse : Specifies the compare value.
00610   *         This parameter must be a value between 0x0000 and 0xFFFF.
00611   * @retval HAL status
00612   */
00613 HAL_StatusTypeDef HAL_LPTIM_OnePulse_Start_IT(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Pulse)
00614 {
00615   /* Check the parameters */
00616   assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
00617   assert_param(IS_LPTIM_PERIOD(Period));
00618   assert_param(IS_LPTIM_PULSE(Pulse));
00619                
00620   /* Set the LPTIM state */
00621   hlptim->State= HAL_LPTIM_STATE_BUSY;
00622   
00623   /* Reset WAVE bit to set one pulse mode */
00624   hlptim->Instance->CFGR &= ~LPTIM_CFGR_WAVE;
00625   
00626   /* Enable Autoreload write complete interrupt */
00627   __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_ARROK);
00628   
00629   /* Enable Compare write complete interrupt */
00630   __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_CMPOK);
00631   
00632   /* Enable Autoreload match interrupt */
00633   __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_ARRM);
00634   
00635   /* Enable Compare match interrupt */
00636   __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_CMPM);
00637   
00638   /* If external trigger source is used, then enable external trigger interrupt */
00639   if ((hlptim->Init.Trigger.Source) !=  LPTIM_TRIGSOURCE_SOFTWARE)
00640   {
00641     /* Enable external trigger interrupt */
00642     __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_EXTTRIG);
00643   }
00644   
00645   /* Enable the Peripheral */
00646   __HAL_LPTIM_ENABLE(hlptim);
00647   
00648   /* Load the period value in the autoreload register */
00649   __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
00650   
00651   /* Load the pulse value in the compare register */
00652   __HAL_LPTIM_COMPARE_SET(hlptim, Pulse);
00653   
00654   /* Start timer in continuous mode */
00655   __HAL_LPTIM_START_SINGLE(hlptim);
00656     
00657   /* Change the TIM state*/
00658   hlptim->State= HAL_LPTIM_STATE_READY;
00659   
00660   /* Return function status */
00661   return HAL_OK;
00662 }
00663 
00664 /**
00665   * @brief  Stop the LPTIM One pulse generation in interrupt mode.
00666   * @param  hlptim : LPTIM handle
00667   * @retval HAL status
00668   */
00669 HAL_StatusTypeDef HAL_LPTIM_OnePulse_Stop_IT(LPTIM_HandleTypeDef *hlptim)
00670 {
00671   /* Check the parameters */
00672   assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
00673                
00674   /* Set the LPTIM state */
00675   hlptim->State= HAL_LPTIM_STATE_BUSY;
00676   
00677   /* Disable the Peripheral */
00678   __HAL_LPTIM_DISABLE(hlptim);
00679   
00680   /* Disable Autoreload write complete interrupt */
00681   __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_ARROK);
00682   
00683   /* Disable Compare write complete interrupt */
00684   __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_CMPOK);
00685   
00686   /* Disable Autoreload match interrupt */
00687   __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_ARRM);
00688   
00689   /* Disable Compare match interrupt */
00690   __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_CMPM);
00691   
00692   /* If external trigger source is used, then disable external trigger interrupt */
00693   if ((hlptim->Init.Trigger.Source) !=  LPTIM_TRIGSOURCE_SOFTWARE)
00694   {
00695     /* Disable external trigger interrupt */
00696     __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_EXTTRIG);
00697   }
00698   
00699   /* Change the TIM state*/
00700   hlptim->State= HAL_LPTIM_STATE_READY;
00701   
00702   /* Return function status */
00703   return HAL_OK;
00704 }
00705 
00706 /**
00707   * @brief  Start the LPTIM in Set once mode.
00708   * @param  hlptim : LPTIM handle
00709   * @param  Period : Specifies the Autoreload value.
00710   *         This parameter must be a value between 0x0000 and 0xFFFF.
00711   * @param  Pulse : Specifies the compare value.
00712   *         This parameter must be a value between 0x0000 and 0xFFFF.
00713   * @retval HAL status
00714   */
00715 HAL_StatusTypeDef HAL_LPTIM_SetOnce_Start(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Pulse)
00716 {
00717   /* Check the parameters */
00718   assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
00719   assert_param(IS_LPTIM_PERIOD(Period));
00720   assert_param(IS_LPTIM_PULSE(Pulse));
00721                
00722   /* Set the LPTIM state */
00723   hlptim->State= HAL_LPTIM_STATE_BUSY;
00724   
00725   /* Set WAVE bit to enable the set once mode */
00726   hlptim->Instance->CFGR |= LPTIM_CFGR_WAVE;
00727   
00728   /* Enable the Peripheral */
00729   __HAL_LPTIM_ENABLE(hlptim);
00730   
00731   /* Load the period value in the autoreload register */
00732   __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
00733   
00734   /* Load the pulse value in the compare register */
00735   __HAL_LPTIM_COMPARE_SET(hlptim, Pulse);
00736   
00737   /* Start timer in continuous mode */
00738   __HAL_LPTIM_START_SINGLE(hlptim);
00739     
00740   /* Change the TIM state*/
00741   hlptim->State= HAL_LPTIM_STATE_READY;
00742   
00743   /* Return function status */
00744   return HAL_OK;
00745 }
00746 
00747 /**
00748   * @brief  Stop the LPTIM Set once mode.
00749   * @param  hlptim : LPTIM handle
00750   * @retval HAL status
00751   */
00752 HAL_StatusTypeDef HAL_LPTIM_SetOnce_Stop(LPTIM_HandleTypeDef *hlptim)
00753 {
00754   /* Check the parameters */
00755   assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
00756                
00757   /* Set the LPTIM state */
00758   hlptim->State= HAL_LPTIM_STATE_BUSY;
00759   
00760   /* Disable the Peripheral */
00761   __HAL_LPTIM_DISABLE(hlptim);
00762 
00763   /* Change the TIM state*/
00764   hlptim->State= HAL_LPTIM_STATE_READY;
00765   
00766   /* Return function status */
00767   return HAL_OK;
00768 }
00769 
00770 /**
00771   * @brief  Start the LPTIM Set once mode in interrupt mode.
00772   * @param  hlptim : LPTIM handle
00773   * @param  Period : Specifies the Autoreload value.
00774   *         This parameter must be a value between 0x0000 and 0xFFFF.
00775   * @param  Pulse : Specifies the compare value.
00776   *         This parameter must be a value between 0x0000 and 0xFFFF.
00777   * @retval HAL status
00778   */
00779 HAL_StatusTypeDef HAL_LPTIM_SetOnce_Start_IT(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Pulse)
00780 {
00781   /* Check the parameters */
00782   assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
00783   assert_param(IS_LPTIM_PERIOD(Period));
00784   assert_param(IS_LPTIM_PULSE(Pulse));
00785                
00786   /* Set the LPTIM state */
00787   hlptim->State= HAL_LPTIM_STATE_BUSY;
00788   
00789   /* Set WAVE bit to enable the set once mode */
00790   hlptim->Instance->CFGR |= LPTIM_CFGR_WAVE;
00791   
00792   /* Enable Autoreload write complete interrupt */
00793   __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_ARROK);
00794   
00795   /* Enable Compare write complete interrupt */
00796   __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_CMPOK);
00797   
00798   /* Enable Autoreload match interrupt */
00799   __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_ARRM);
00800   
00801   /* Enable Compare match interrupt */
00802   __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_CMPM);
00803   
00804   /* If external trigger source is used, then enable external trigger interrupt */
00805   if ((hlptim->Init.Trigger.Source) !=  LPTIM_TRIGSOURCE_SOFTWARE)
00806   {
00807     /* Enable external trigger interrupt */
00808     __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_EXTTRIG);
00809   }  
00810   
00811   /* Enable the Peripheral */
00812   __HAL_LPTIM_ENABLE(hlptim);
00813   
00814   /* Load the period value in the autoreload register */
00815   __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
00816   
00817   /* Load the pulse value in the compare register */
00818   __HAL_LPTIM_COMPARE_SET(hlptim, Pulse);
00819   
00820   /* Start timer in continuous mode */
00821   __HAL_LPTIM_START_SINGLE(hlptim);
00822     
00823   /* Change the TIM state*/
00824   hlptim->State= HAL_LPTIM_STATE_READY;
00825   
00826   /* Return function status */
00827   return HAL_OK;
00828 }
00829 
00830 /**
00831   * @brief  Stop the LPTIM Set once mode in interrupt mode.
00832   * @param  hlptim : LPTIM handle
00833   * @retval HAL status
00834   */
00835 HAL_StatusTypeDef HAL_LPTIM_SetOnce_Stop_IT(LPTIM_HandleTypeDef *hlptim)
00836 {
00837   /* Check the parameters */
00838   assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
00839                
00840   /* Set the LPTIM state */
00841   hlptim->State= HAL_LPTIM_STATE_BUSY;
00842   
00843   /* Disable the Peripheral */
00844   __HAL_LPTIM_DISABLE(hlptim);
00845 
00846   /* Disable Autoreload write complete interrupt */
00847   __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_ARROK);
00848   
00849   /* Disable Compare write complete interrupt */
00850   __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_CMPOK);
00851   
00852   /* Disable Autoreload match interrupt */
00853   __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_ARRM);
00854   
00855   /* Disable Compare match interrupt */
00856   __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_CMPM);
00857   
00858   /* If external trigger source is used, then disable external trigger interrupt */
00859   if ((hlptim->Init.Trigger.Source) !=  LPTIM_TRIGSOURCE_SOFTWARE)
00860   {
00861     /* Disable external trigger interrupt */
00862     __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_EXTTRIG);
00863   } 
00864   
00865   /* Change the TIM state*/
00866   hlptim->State= HAL_LPTIM_STATE_READY;
00867   
00868   /* Return function status */
00869   return HAL_OK;
00870 }
00871 
00872 /**
00873   * @brief  Start the Encoder interface.
00874   * @param  hlptim : LPTIM handle
00875   * @param  Period : Specifies the Autoreload value.
00876   *         This parameter must be a value between 0x0000 and 0xFFFF.
00877   * @retval HAL status
00878   */
00879 HAL_StatusTypeDef HAL_LPTIM_Encoder_Start(LPTIM_HandleTypeDef *hlptim, uint32_t Period)
00880 {
00881   HAL_StatusTypeDef status = HAL_OK;
00882   uint32_t          tmpcfgr;
00883 
00884   /* Check the parameters */
00885   assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
00886   assert_param(IS_LPTIM_PERIOD(Period));
00887   assert_param(hlptim->Init.Clock.Source == LPTIM_CLOCKSOURCE_APBCLOCK_LPOSC);
00888   assert_param(hlptim->Init.Clock.Prescaler == LPTIM_PRESCALER_DIV1);
00889   assert_param(IS_LPTIM_CLOCK_POLARITY(hlptim->Init.UltraLowPowerClock.Polarity));
00890 
00891   /* Encoder feature is only available for LPTIM1 instance */
00892   if (hlptim->Instance == LPTIM1)
00893   {
00894     /* Set the LPTIM state */
00895     hlptim->State= HAL_LPTIM_STATE_BUSY;
00896 
00897     /* Get the LPTIMx CFGR value */
00898     tmpcfgr = hlptim->Instance->CFGR;
00899 
00900     /* Clear CKPOL bits */
00901     tmpcfgr &= (uint32_t)(~LPTIM_CFGR_CKPOL);
00902 
00903     /* Set Input polarity */
00904     tmpcfgr |=  hlptim->Init.UltraLowPowerClock.Polarity;
00905 
00906     /* Write to LPTIMx CFGR */
00907     hlptim->Instance->CFGR = tmpcfgr;
00908 
00909     /* Set ENC bit to enable the encoder interface */
00910     hlptim->Instance->CFGR |= LPTIM_CFGR_ENC;
00911 
00912     /* Enable the Peripheral */
00913     __HAL_LPTIM_ENABLE(hlptim);
00914 
00915     /* Load the period value in the autoreload register */
00916     __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
00917 
00918     /* Start timer in continuous mode */
00919     __HAL_LPTIM_START_CONTINUOUS(hlptim);
00920 
00921     /* Change the TIM state*/
00922     hlptim->State= HAL_LPTIM_STATE_READY;
00923   }
00924   else
00925   {
00926     status = HAL_ERROR;
00927   }
00928 
00929   /* Return function status */
00930   return status;
00931 }
00932 
00933 /**
00934   * @brief  Stop the Encoder interface.
00935   * @param  hlptim : LPTIM handle
00936   * @retval HAL status
00937   */
00938 HAL_StatusTypeDef HAL_LPTIM_Encoder_Stop(LPTIM_HandleTypeDef *hlptim)
00939 {
00940   /* Check the parameters */
00941   assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
00942                
00943   /* Set the LPTIM state */
00944   hlptim->State= HAL_LPTIM_STATE_BUSY;
00945   
00946   /* Disable the Peripheral */
00947   __HAL_LPTIM_DISABLE(hlptim);
00948   
00949   /* Reset ENC bit to disable the encoder interface */
00950   hlptim->Instance->CFGR &= ~LPTIM_CFGR_ENC;
00951   
00952   /* Change the TIM state*/
00953   hlptim->State= HAL_LPTIM_STATE_READY;
00954   
00955   /* Return function status */
00956   return HAL_OK;
00957 }
00958 
00959 /**
00960   * @brief  Start the Encoder interface in interrupt mode.
00961   * @param  hlptim : LPTIM handle
00962   * @param  Period : Specifies the Autoreload value.
00963   *         This parameter must be a value between 0x0000 and 0xFFFF.
00964   * @retval HAL status
00965   */
00966 HAL_StatusTypeDef HAL_LPTIM_Encoder_Start_IT(LPTIM_HandleTypeDef *hlptim, uint32_t Period)
00967 {
00968   HAL_StatusTypeDef status = HAL_OK;
00969   uint32_t          tmpcfgr;
00970 
00971   /* Check the parameters */
00972   assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
00973   assert_param(IS_LPTIM_PERIOD(Period));
00974   assert_param(hlptim->Init.Clock.Source == LPTIM_CLOCKSOURCE_APBCLOCK_LPOSC);
00975   assert_param(hlptim->Init.Clock.Prescaler == LPTIM_PRESCALER_DIV1);
00976   assert_param(IS_LPTIM_CLOCK_POLARITY(hlptim->Init.UltraLowPowerClock.Polarity));
00977 
00978   /* Encoder feature is only available for LPTIM1 instance */
00979   if (hlptim->Instance == LPTIM1)
00980   {
00981     /* Set the LPTIM state */
00982     hlptim->State= HAL_LPTIM_STATE_BUSY;
00983 
00984     /* Configure edge sensitivity for encoder mode */
00985     /* Get the LPTIMx CFGR value */
00986     tmpcfgr = hlptim->Instance->CFGR;
00987 
00988     /* Clear CKPOL bits */
00989     tmpcfgr &= (uint32_t)(~LPTIM_CFGR_CKPOL);
00990 
00991     /* Set Input polarity */
00992     tmpcfgr |=  hlptim->Init.UltraLowPowerClock.Polarity;
00993 
00994     /* Write to LPTIMx CFGR */
00995     hlptim->Instance->CFGR = tmpcfgr;
00996 
00997     /* Set ENC bit to enable the encoder interface */
00998     hlptim->Instance->CFGR |= LPTIM_CFGR_ENC;
00999 
01000     /* Enable "switch to down direction" interrupt */
01001     __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_DOWN);
01002 
01003     /* Enable "switch to up direction" interrupt */
01004     __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_UP);  
01005 
01006     /* Enable the Peripheral */
01007     __HAL_LPTIM_ENABLE(hlptim);
01008 
01009     /* Load the period value in the autoreload register */
01010     __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
01011 
01012     /* Start timer in continuous mode */
01013     __HAL_LPTIM_START_CONTINUOUS(hlptim);
01014 
01015     /* Change the TIM state*/
01016     hlptim->State= HAL_LPTIM_STATE_READY;
01017   }
01018   else
01019   {
01020     status = HAL_ERROR;
01021   }
01022 
01023   /* Return function status */
01024   return status;
01025 }
01026 
01027 /**
01028   * @brief  Stop the Encoder interface in interrupt mode.
01029   * @param  hlptim : LPTIM handle
01030   * @retval HAL status
01031   */
01032 HAL_StatusTypeDef HAL_LPTIM_Encoder_Stop_IT(LPTIM_HandleTypeDef *hlptim)
01033 {
01034   /* Check the parameters */
01035   assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
01036                
01037   /* Set the LPTIM state */
01038   hlptim->State= HAL_LPTIM_STATE_BUSY;
01039   
01040   /* Disable the Peripheral */
01041   __HAL_LPTIM_DISABLE(hlptim);
01042   
01043   /* Reset ENC bit to disable the encoder interface */
01044   hlptim->Instance->CFGR &= ~LPTIM_CFGR_ENC;
01045   
01046   /* Disable "switch to down direction" interrupt */
01047   __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_DOWN);
01048   
01049   /* Disable "switch to up direction" interrupt */
01050   __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_UP); 
01051   
01052   /* Change the TIM state*/
01053   hlptim->State= HAL_LPTIM_STATE_READY;
01054   
01055   /* Return function status */
01056   return HAL_OK;
01057 }
01058 
01059 /**
01060   * @brief  Start the Timeout function.
01061   * @note   The first trigger event will start the timer, any successive
01062   *         trigger event will reset the counter and the timer restarts.
01063   * @param  hlptim : LPTIM handle
01064   * @param  Period : Specifies the Autoreload value.
01065   *         This parameter must be a value between 0x0000 and 0xFFFF.
01066   * @param  Timeout : Specifies the TimeOut value to rest the counter.
01067   *         This parameter must be a value between 0x0000 and 0xFFFF.
01068   * @retval HAL status
01069   */
01070 HAL_StatusTypeDef HAL_LPTIM_TimeOut_Start(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Timeout)
01071 {
01072   /* Check the parameters */
01073   assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
01074   assert_param(IS_LPTIM_PERIOD(Period));
01075   assert_param(IS_LPTIM_PULSE(Timeout));
01076                
01077   /* Set the LPTIM state */
01078   hlptim->State= HAL_LPTIM_STATE_BUSY;
01079  
01080   /* Set TIMOUT bit to enable the timeout function */
01081   hlptim->Instance->CFGR |= LPTIM_CFGR_TIMOUT;
01082   
01083   /* Enable the Peripheral */
01084   __HAL_LPTIM_ENABLE(hlptim);
01085   
01086   /* Load the period value in the autoreload register */
01087   __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
01088   
01089   /* Load the Timeout value in the compare register */
01090   __HAL_LPTIM_COMPARE_SET(hlptim, Timeout);
01091   
01092   /* Start timer in continuous mode */
01093   __HAL_LPTIM_START_CONTINUOUS(hlptim);
01094     
01095   /* Change the TIM state*/
01096   hlptim->State= HAL_LPTIM_STATE_READY;
01097   
01098   /* Return function status */
01099   return HAL_OK;
01100 }
01101 
01102 /**
01103   * @brief  Stop the Timeout function.
01104   * @param  hlptim : LPTIM handle
01105   * @retval HAL status
01106   */
01107 HAL_StatusTypeDef HAL_LPTIM_TimeOut_Stop(LPTIM_HandleTypeDef *hlptim)
01108 {
01109   /* Check the parameters */
01110   assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
01111   
01112   /* Set the LPTIM state */
01113   hlptim->State= HAL_LPTIM_STATE_BUSY;
01114   
01115   /* Disable the Peripheral */
01116   __HAL_LPTIM_DISABLE(hlptim);
01117   
01118   /* Reset TIMOUT bit to enable the timeout function */
01119   hlptim->Instance->CFGR &= ~LPTIM_CFGR_TIMOUT;
01120   
01121   /* Change the TIM state*/
01122   hlptim->State= HAL_LPTIM_STATE_READY;
01123   
01124   /* Return function status */
01125   return HAL_OK;
01126 }
01127 
01128 /**
01129   * @brief  Start the Timeout function in interrupt mode.
01130   * @note   The first trigger event will start the timer, any successive
01131   *         trigger event will reset the counter and the timer restarts.
01132   * @param  hlptim : LPTIM handle
01133   * @param  Period : Specifies the Autoreload value.
01134   *         This parameter must be a value between 0x0000 and 0xFFFF.
01135   * @param  Timeout : Specifies the TimeOut value to rest the counter.
01136   *         This parameter must be a value between 0x0000 and 0xFFFF.
01137   * @retval HAL status
01138   */
01139 HAL_StatusTypeDef HAL_LPTIM_TimeOut_Start_IT(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Timeout)
01140 {
01141   /* Check the parameters */
01142   assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
01143   assert_param(IS_LPTIM_PERIOD(Period));
01144   assert_param(IS_LPTIM_PULSE(Timeout));
01145                
01146   /* Set the LPTIM state */
01147   hlptim->State= HAL_LPTIM_STATE_BUSY;
01148  
01149   /* Set TIMOUT bit to enable the timeout function */
01150   hlptim->Instance->CFGR |= LPTIM_CFGR_TIMOUT;
01151   
01152   /* Enable Compare match interrupt */
01153   __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_CMPM);
01154   
01155   /* Enable the Peripheral */
01156   __HAL_LPTIM_ENABLE(hlptim);
01157   
01158   /* Load the period value in the autoreload register */
01159   __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
01160   
01161   /* Load the Timeout value in the compare register */
01162   __HAL_LPTIM_COMPARE_SET(hlptim, Timeout);
01163   
01164   /* Start timer in continuous mode */
01165   __HAL_LPTIM_START_CONTINUOUS(hlptim);
01166     
01167   /* Change the TIM state*/
01168   hlptim->State= HAL_LPTIM_STATE_READY;
01169   
01170   /* Return function status */
01171   return HAL_OK;
01172 }
01173 
01174 /**
01175   * @brief  Stop the Timeout function in interrupt mode.
01176   * @param  hlptim : LPTIM handle
01177   * @retval HAL status
01178   */
01179 HAL_StatusTypeDef HAL_LPTIM_TimeOut_Stop_IT(LPTIM_HandleTypeDef *hlptim)
01180 {
01181   /* Check the parameters */
01182   assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
01183   
01184   /* Set the LPTIM state */
01185   hlptim->State= HAL_LPTIM_STATE_BUSY;
01186   
01187   /* Disable the Peripheral */
01188   __HAL_LPTIM_DISABLE(hlptim);
01189   
01190   /* Reset TIMOUT bit to enable the timeout function */
01191   hlptim->Instance->CFGR &= ~LPTIM_CFGR_TIMOUT;
01192   
01193   /* Disable Compare match interrupt */
01194   __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_CMPM);
01195   
01196   /* Change the TIM state*/
01197   hlptim->State= HAL_LPTIM_STATE_READY;
01198   
01199   /* Return function status */
01200   return HAL_OK;
01201 }
01202 
01203 /**
01204   * @brief  Start the Counter mode.
01205   * @param  hlptim : LPTIM handle
01206   * @param  Period : Specifies the Autoreload value.
01207   *         This parameter must be a value between 0x0000 and 0xFFFF.
01208   * @retval HAL status
01209   */
01210 HAL_StatusTypeDef HAL_LPTIM_Counter_Start(LPTIM_HandleTypeDef *hlptim, uint32_t Period)
01211 {
01212   /* Check the parameters */
01213   assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
01214   assert_param(IS_LPTIM_PERIOD(Period));
01215                
01216   /* Set the LPTIM state */
01217   hlptim->State= HAL_LPTIM_STATE_BUSY;
01218   
01219   /* If clock source is not ULPTIM clock and counter source is external, then it must not be prescaled */
01220   if((hlptim->Init.Clock.Source != LPTIM_CLOCKSOURCE_ULPTIM) && (hlptim->Init.CounterSource == LPTIM_COUNTERSOURCE_EXTERNAL))
01221   {
01222     /* Check if clock is prescaled */
01223     assert_param(IS_LPTIM_CLOCK_PRESCALERDIV1(hlptim->Init.Clock.Prescaler));
01224     /* Set clock prescaler to 0 */
01225     hlptim->Instance->CFGR &= ~LPTIM_CFGR_PRESC;
01226   }
01227 
01228   /* Enable the Peripheral */
01229   __HAL_LPTIM_ENABLE(hlptim);
01230   
01231   /* Load the period value in the autoreload register */
01232   __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
01233   
01234   /* Start timer in continuous mode */
01235   __HAL_LPTIM_START_CONTINUOUS(hlptim);
01236     
01237   /* Change the TIM state*/
01238   hlptim->State= HAL_LPTIM_STATE_READY;
01239   
01240   /* Return function status */
01241   return HAL_OK;
01242 }
01243 
01244 /**
01245   * @brief  Stop the Counter mode.
01246   * @param  hlptim : LPTIM handle
01247   * @retval HAL status
01248   */
01249 HAL_StatusTypeDef HAL_LPTIM_Counter_Stop(LPTIM_HandleTypeDef *hlptim)
01250 {
01251   /* Check the parameters */
01252   assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
01253   
01254   /* Set the LPTIM state */
01255   hlptim->State= HAL_LPTIM_STATE_BUSY;
01256   
01257   /* Disable the Peripheral */
01258   __HAL_LPTIM_DISABLE(hlptim);
01259   
01260   /* Change the TIM state*/
01261   hlptim->State= HAL_LPTIM_STATE_READY;
01262   
01263   /* Return function status */
01264   return HAL_OK;
01265 }
01266 
01267 /**
01268   * @brief  Start the Counter mode in interrupt mode.
01269   * @param  hlptim : LPTIM handle
01270   * @param  Period : Specifies the Autoreload value.
01271   *         This parameter must be a value between 0x0000 and 0xFFFF.
01272   * @retval HAL status
01273   */
01274 HAL_StatusTypeDef HAL_LPTIM_Counter_Start_IT(LPTIM_HandleTypeDef *hlptim, uint32_t Period)
01275 {
01276   /* Check the parameters */
01277   assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
01278   assert_param(IS_LPTIM_PERIOD(Period));
01279                
01280   /* Set the LPTIM state */
01281   hlptim->State= HAL_LPTIM_STATE_BUSY;
01282   
01283   /* If clock source is not ULPTIM clock and counter source is external, then it must not be prescaled */
01284   if((hlptim->Init.Clock.Source != LPTIM_CLOCKSOURCE_ULPTIM) && (hlptim->Init.CounterSource == LPTIM_COUNTERSOURCE_EXTERNAL))
01285   {
01286     /* Check if clock is prescaled */
01287     assert_param(IS_LPTIM_CLOCK_PRESCALERDIV1(hlptim->Init.Clock.Prescaler));
01288     /* Set clock prescaler to 0 */
01289     hlptim->Instance->CFGR &= ~LPTIM_CFGR_PRESC;
01290   }
01291   
01292   /* Enable Autoreload write complete interrupt */
01293   __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_ARROK);
01294   
01295   /* Enable Autoreload match interrupt */
01296   __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_ARRM);
01297   
01298   /* Enable the Peripheral */
01299   __HAL_LPTIM_ENABLE(hlptim);
01300   
01301   /* Load the period value in the autoreload register */
01302   __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
01303   
01304   /* Start timer in continuous mode */
01305   __HAL_LPTIM_START_CONTINUOUS(hlptim);
01306     
01307   /* Change the TIM state*/
01308   hlptim->State= HAL_LPTIM_STATE_READY;
01309   
01310   /* Return function status */
01311   return HAL_OK;
01312 }
01313 
01314 /**
01315   * @brief  Stop the Counter mode in interrupt mode.
01316   * @param  hlptim : LPTIM handle
01317   * @retval HAL status
01318   */
01319 HAL_StatusTypeDef HAL_LPTIM_Counter_Stop_IT(LPTIM_HandleTypeDef *hlptim)
01320 {
01321   /* Check the parameters */
01322   assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
01323   
01324   /* Set the LPTIM state */
01325   hlptim->State= HAL_LPTIM_STATE_BUSY;
01326   
01327   /* Disable the Peripheral */
01328   __HAL_LPTIM_DISABLE(hlptim);
01329   
01330   /* Disable Autoreload write complete interrupt */
01331   __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_ARROK);
01332   
01333   /* Disable Autoreload match interrupt */
01334   __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_ARRM);
01335   
01336   /* Change the TIM state*/
01337   hlptim->State= HAL_LPTIM_STATE_READY;
01338   
01339   /* Return function status */
01340   return HAL_OK;
01341 }
01342 
01343 /**
01344   * @}
01345   */
01346 
01347 /** @defgroup LPTIM_Exported_Functions_Group3 LPTIM Read operation functions 
01348  *  @brief  Read operation functions.
01349  *
01350 @verbatim   
01351   ==============================================================================
01352                   ##### LPTIM Read operation functions #####
01353   ==============================================================================  
01354 [..]  This section provides LPTIM Reading functions.
01355       (+) Read the counter value.
01356       (+) Read the period (Auto-reload) value.
01357       (+) Read the pulse (Compare)value.
01358 @endverbatim
01359   * @{
01360   */
01361 
01362 /**
01363   * @brief  Return the current counter value.
01364   * @param  hlptim: LPTIM handle
01365   * @retval Counter value.
01366   */
01367 uint32_t HAL_LPTIM_ReadCounter(LPTIM_HandleTypeDef *hlptim)
01368 {
01369     /* Check the parameters */
01370   assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
01371   
01372   return (hlptim->Instance->CNT);
01373 }
01374 
01375 /**
01376   * @brief  Return the current Autoreload (Period) value.
01377   * @param  hlptim: LPTIM handle
01378   * @retval Autoreload value.
01379   */
01380 uint32_t HAL_LPTIM_ReadAutoReload(LPTIM_HandleTypeDef *hlptim)
01381 {
01382     /* Check the parameters */
01383   assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
01384   
01385   return (hlptim->Instance->ARR);
01386 }
01387 
01388 /**
01389   * @brief  Return the current Compare (Pulse) value.
01390   * @param  hlptim: LPTIM handle
01391   * @retval Compare value.
01392   */
01393 uint32_t HAL_LPTIM_ReadCompare(LPTIM_HandleTypeDef *hlptim)
01394 {
01395     /* Check the parameters */
01396   assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
01397   
01398   return (hlptim->Instance->CMP);
01399 }
01400 
01401 /**
01402   * @}
01403   */
01404 
01405 
01406 
01407 /** @defgroup LPTIM_Exported_Functions_Group4 LPTIM IRQ handler and callbacks
01408  *  @brief  LPTIM  IRQ handler.
01409  *
01410 @verbatim   
01411   ==============================================================================
01412                       ##### LPTIM IRQ handler and callbacks  #####
01413   ==============================================================================  
01414 [..]  This section provides LPTIM IRQ handler and callback functions called within 
01415       the IRQ handler.
01416 
01417 @endverbatim
01418   * @{
01419   */
01420 
01421 /**
01422   * @brief  Handle LPTIM interrupt request.
01423   * @param  hlptim: LPTIM handle
01424   * @retval None
01425   */
01426 void HAL_LPTIM_IRQHandler(LPTIM_HandleTypeDef *hlptim)
01427 {
01428   /* Compare match interrupt */
01429   if(__HAL_LPTIM_GET_FLAG(hlptim, LPTIM_FLAG_CMPM) != RESET)
01430   {
01431     if(__HAL_LPTIM_GET_IT_SOURCE(hlptim, LPTIM_IT_CMPM) != RESET)
01432     {
01433       /* Clear Compare match flag */
01434       __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_CMPM);
01435       
01436       /* Compare match Callback */
01437       HAL_LPTIM_CompareMatchCallback(hlptim);      
01438     }
01439   }
01440   
01441   /* Autoreload match interrupt */
01442   if(__HAL_LPTIM_GET_FLAG(hlptim, LPTIM_FLAG_ARRM) != RESET)
01443   {
01444     if(__HAL_LPTIM_GET_IT_SOURCE(hlptim, LPTIM_IT_ARRM) != RESET)
01445     {
01446       /* Clear Autoreload match flag */
01447       __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_ARRM);
01448       
01449       /* Autoreload match Callback */
01450       HAL_LPTIM_AutoReloadMatchCallback(hlptim);      
01451     }
01452   }
01453   
01454   /* Trigger detected interrupt */
01455   if(__HAL_LPTIM_GET_FLAG(hlptim, LPTIM_FLAG_EXTTRIG) != RESET)
01456   {
01457     if(__HAL_LPTIM_GET_IT_SOURCE(hlptim, LPTIM_IT_EXTTRIG) != RESET)
01458     {
01459       /* Clear Trigger detected flag */
01460       __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_EXTTRIG);
01461       
01462       /* Trigger detected callback */
01463       HAL_LPTIM_TriggerCallback(hlptim);      
01464     }
01465   }
01466   
01467   /* Compare write interrupt */
01468   if(__HAL_LPTIM_GET_FLAG(hlptim, LPTIM_FLAG_CMPOK) != RESET)
01469   {
01470     if(__HAL_LPTIM_GET_IT_SOURCE(hlptim, LPTIM_IT_CMPOK) != RESET)
01471     {
01472       /* Clear Compare write flag */
01473       __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_CMPOK);
01474       
01475       /* Compare write Callback */
01476       HAL_LPTIM_CompareWriteCallback(hlptim);      
01477     }
01478   }
01479   
01480   /* Autoreload write interrupt */
01481   if(__HAL_LPTIM_GET_FLAG(hlptim, LPTIM_FLAG_ARROK) != RESET)
01482   {
01483     if(__HAL_LPTIM_GET_IT_SOURCE(hlptim, LPTIM_IT_ARROK) != RESET)
01484     {
01485       /* Clear Autoreload write flag */
01486       __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_ARROK);
01487       
01488       /* Autoreload write Callback */
01489       HAL_LPTIM_AutoReloadWriteCallback(hlptim);      
01490     }
01491   }
01492   
01493   /* Direction counter changed from Down to Up interrupt */
01494   if(__HAL_LPTIM_GET_FLAG(hlptim, LPTIM_FLAG_UP) != RESET)
01495   {
01496     if(__HAL_LPTIM_GET_IT_SOURCE(hlptim, LPTIM_IT_UP) != RESET)
01497     {
01498       /* Clear Direction counter changed from Down to Up flag */
01499       __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_UP);
01500       
01501       /* Direction counter changed from Down to Up Callback */
01502       HAL_LPTIM_DirectionUpCallback(hlptim);      
01503     }
01504   }
01505   
01506   /* Direction counter changed from Up to Down interrupt */
01507   if(__HAL_LPTIM_GET_FLAG(hlptim, LPTIM_FLAG_DOWN) != RESET)
01508   {
01509     if(__HAL_LPTIM_GET_IT_SOURCE(hlptim, LPTIM_IT_DOWN) != RESET)
01510     {
01511       /* Clear Direction counter changed from Up to Down flag */
01512       __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_DOWN);
01513       
01514       /* Direction counter changed from Up to Down Callback */
01515       HAL_LPTIM_DirectionDownCallback(hlptim);      
01516     }
01517   }
01518 }
01519 
01520 /**
01521   * @brief  Compare match callback in non-blocking mode.
01522   * @param  hlptim : LPTIM handle
01523   * @retval None
01524   */
01525 __weak void HAL_LPTIM_CompareMatchCallback(LPTIM_HandleTypeDef *hlptim)
01526 {
01527   /* Prevent unused argument(s) compilation warning */
01528   UNUSED(hlptim);
01529 
01530   /* NOTE : This function should not be modified, when the callback is needed,
01531             the HAL_LPTIM_CompareMatchCallback could be implemented in the user file
01532    */  
01533 }
01534 
01535 /**
01536   * @brief  Autoreload match callback in non-blocking mode.
01537   * @param  hlptim : LPTIM handle
01538   * @retval None
01539   */
01540 __weak void HAL_LPTIM_AutoReloadMatchCallback(LPTIM_HandleTypeDef *hlptim)
01541 {
01542   /* Prevent unused argument(s) compilation warning */
01543   UNUSED(hlptim);
01544 
01545   /* NOTE : This function should not be modified, when the callback is needed,
01546             the HAL_LPTIM_AutoReloadMatchCallback could be implemented in the user file
01547    */  
01548 }
01549 
01550 /**
01551   * @brief  Trigger detected callback in non-blocking mode.
01552   * @param  hlptim : LPTIM handle
01553   * @retval None
01554   */
01555 __weak void HAL_LPTIM_TriggerCallback(LPTIM_HandleTypeDef *hlptim)
01556 {
01557   /* Prevent unused argument(s) compilation warning */
01558   UNUSED(hlptim);
01559 
01560   /* NOTE : This function should not be modified, when the callback is needed,
01561             the HAL_LPTIM_TriggerCallback could be implemented in the user file
01562    */  
01563 }
01564 
01565 /**
01566   * @brief  Compare write callback in non-blocking mode.
01567   * @param  hlptim : LPTIM handle
01568   * @retval None
01569   */
01570 __weak void HAL_LPTIM_CompareWriteCallback(LPTIM_HandleTypeDef *hlptim)
01571 {
01572   /* Prevent unused argument(s) compilation warning */
01573   UNUSED(hlptim);
01574 
01575   /* NOTE : This function should not be modified, when the callback is needed,
01576             the HAL_LPTIM_CompareWriteCallback could be implemented in the user file
01577    */  
01578 }
01579 
01580 /**
01581   * @brief  Autoreload write callback in non-blocking mode. 
01582   * @param  hlptim : LPTIM handle
01583   * @retval None
01584   */
01585 __weak void HAL_LPTIM_AutoReloadWriteCallback(LPTIM_HandleTypeDef *hlptim)
01586 {
01587   /* Prevent unused argument(s) compilation warning */
01588   UNUSED(hlptim);
01589 
01590   /* NOTE : This function should not be modified, when the callback is needed,
01591             the HAL_LPTIM_AutoReloadWriteCallback could be implemented in the user file
01592    */  
01593 }
01594 
01595 /**
01596   * @brief  Direction counter changed from Down to Up callback in non-blocking mode.
01597   * @param  hlptim : LPTIM handle
01598   * @retval None
01599   */
01600 __weak void HAL_LPTIM_DirectionUpCallback(LPTIM_HandleTypeDef *hlptim)
01601 {
01602   /* Prevent unused argument(s) compilation warning */
01603   UNUSED(hlptim);
01604 
01605   /* NOTE : This function should not be modified, when the callback is needed,
01606             the HAL_LPTIM_DirectionUpCallback could be implemented in the user file
01607    */  
01608 }
01609 
01610 /**
01611   * @brief  Direction counter changed from Up to Down callback in non-blocking mode.
01612   * @param  hlptim : LPTIM handle
01613   * @retval None
01614   */
01615 __weak void HAL_LPTIM_DirectionDownCallback(LPTIM_HandleTypeDef *hlptim)
01616 {
01617   /* Prevent unused argument(s) compilation warning */
01618   UNUSED(hlptim);
01619 
01620   /* NOTE : This function should not be modified, when the callback is needed,
01621             the HAL_LPTIM_DirectionDownCallback could be implemented in the user file
01622    */  
01623 }
01624 
01625 /**
01626   * @}
01627   */
01628 
01629 /** @defgroup LPTIM_Exported_Functions_Group5 Peripheral State functions 
01630  *  @brief   Peripheral State functions. 
01631  *
01632 @verbatim   
01633   ==============================================================================
01634                       ##### Peripheral State functions #####
01635   ==============================================================================  
01636     [..]
01637     This subsection permits to get in run-time the status of the peripheral.
01638 
01639 @endverbatim
01640   * @{
01641   */
01642 
01643 /**
01644   * @brief  Return the LPTIM handle state.
01645   * @param  hlptim: LPTIM handle
01646   * @retval HAL state
01647   */
01648 HAL_LPTIM_StateTypeDef HAL_LPTIM_GetState(LPTIM_HandleTypeDef *hlptim)
01649 {
01650   /* Return LPTIM handle state */
01651   return hlptim->State;
01652 }
01653 
01654 /**
01655   * @}
01656   */
01657 
01658 
01659 /**
01660   * @}
01661   */
01662 
01663 #endif /* HAL_LPTIM_MODULE_ENABLED */
01664 /**
01665   * @}
01666   */
01667 
01668 /**
01669   * @}
01670   */
01671 
01672 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/