STM8L15x Standard Peripherals Drivers: stm8l15x_tim4.c Source File

STM8L15x/16x Standard Peripherals Drivers

STM8L15x Standard Peripherals Drivers

stm8l15x_tim4.c

Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    stm8l15x_tim4.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 TIM4 peripheral:
00009   *            - TimeBase management
00010   *            - Interrupts, DMA and flags management
00011   *            - Clocks management
00012   *            - Synchronization management
00013   *
00014   *  @verbatim
00015   *  
00016   *          ===================================================================
00017   *                                 How to use this driver
00018   *          ===================================================================
00019   *          This driver provides functions to configure and initialise the TIM4 
00020   *          peripheral
00021   *          These functions are split in 4 groups: 
00022   *   
00023   *          1. TIM4 TimeBase management: this group includes all needed functions 
00024   *             to configure the TIM Timebase unit:
00025   *                   - Set/Get Prescaler
00026   *                   - Set/Get Autoreload  
00027   *                   - Select the One Pulse mode
00028   *                   - Update Request Configuration
00029   *                   - Update Disable Configuration
00030   *                   - Auto-Preload Configuration 
00031   *                   - Enable/Disable the counter
00032   *                         
00033   *          2. TIM4 interrupts, DMA and flags management
00034   *                   - Enable/Disable interrupt sources
00035   *                   - Get flags status
00036   *                   - Clear flags/ Pending bits
00037   *                   - Enable/Disable DMA requests 
00038   *              
00039   *          3. TIM4 clocks management: this group includes all needed functions 
00040   *             to configure the clock controller unit:
00041   *                   - Select internal clock
00042   *         
00043   *          4. TIM4 synchronization management: this group includes all needed 
00044   *             functions to configure the Synchronization unit:
00045   *                   - Select Input Trigger  
00046   *                   - Select Output Trigger  
00047   *                   - Select Master Slave Mode    
00048   *      
00049   *   
00050   *  @endverbatim
00051   *    
00052   ******************************************************************************
00053   * @attention
00054   *
00055   * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
00056   * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
00057   * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
00058   * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
00059   * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
00060   * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
00061   *
00062   * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2>
00063   ******************************************************************************  
00064   */
00065 
00066 
00067 /* Includes ------------------------------------------------------------------*/
00068 #include "stm8l15x_tim4.h"
00069 
00070 /** @addtogroup STM8L15x_StdPeriph_Driver
00071   * @{
00072   */
00073 
00074 /** @defgroup TIM4
00075   * @brief TIM4 driver modules
00076   * @{
00077   */
00078   
00079 /* Private typedef -----------------------------------------------------------*/
00080 /* Private define ------------------------------------------------------------*/
00081 /* Private macro -------------------------------------------------------------*/
00082 /* Private variables ---------------------------------------------------------*/
00083 /* Private function prototypes -----------------------------------------------*/
00084 /** @defgroup TIM4_Private_Functions
00085   * @{
00086   */
00087 
00088 /** @defgroup TIM4_Group1 TimeBase management functions
00089  *  @brief   TimeBase management functions 
00090  *
00091 @verbatim   
00092  ===============================================================================
00093                        TimeBase management functions
00094  ===============================================================================  
00095   
00096        ===================================================================      
00097               TIM4 Driver: how to use it in Timing(Time base) Mode
00098        =================================================================== 
00099        To use the Timer in Timing(Time base) mode, the following steps are mandatory:
00100        
00101        1. Enable TIM4 clock using CLK_PeripheralClockConfig(CLK_Peripheral_TIM4, ENABLE) function.
00102         
00103        2. Call TIM4_TimeBaseInit() to configure the Time Base unit with the
00104           corresponding configuration.
00105           
00106        3. Enable global interrupts if you need to generate the update interrupt.
00107           
00108        4. Enable the corresponding interrupt using the function TIM4_ITConfig(TIM4_IT_Update) 
00109           
00110        5. Call the TIM4_Cmd(ENABLE) function to enable the TIM4 counter.
00111        
00112        Note1: All other functions can be used separately to modify, if needed,
00113           a specific feature of the Timer. 
00114 
00115 @endverbatim
00116   * @{
00117   */
00118 
00119 /**
00120   * @brief  Deinitializes the TIM4 peripheral registers to their default reset values.
00121   * @param  None
00122   * @retval None
00123   */
00124 void TIM4_DeInit(void)
00125 {
00126   TIM4->CR1   = TIM4_CR1_RESET_VALUE;
00127   TIM4->CR2   = TIM4_CR2_RESET_VALUE;
00128   TIM4->SMCR   = TIM4_SMCR_RESET_VALUE;
00129   TIM4->IER   = TIM4_IER_RESET_VALUE;
00130   TIM4->CNTR   = TIM4_CNTR_RESET_VALUE;
00131   TIM4->PSCR  = TIM4_PSCR_RESET_VALUE;
00132   TIM4->ARR   = TIM4_ARR_RESET_VALUE;
00133   TIM4->SR1   = TIM4_SR1_RESET_VALUE;
00134 }
00135 
00136 /**
00137   * @brief  Initializes the TIM4 Time Base Unit according to the specified parameters.
00138   * @param  TIM4_Prescaler: Prescaler
00139   *          This parameter can be one of the following values:
00140   *            @arg TIM4_Prescaler_1: Time base Prescaler = 1 (No effect)
00141   *            @arg TIM4_Prescaler_2: Time base Prescaler = 2
00142   *            @arg TIM4_Prescaler_4: Time base Prescaler = 4
00143   *            @arg TIM4_Prescaler_8: Time base Prescaler = 8
00144   *            @arg TIM4_Prescaler_16: Time base Prescaler = 16
00145   *            @arg TIM4_Prescaler_32: Time base Prescaler = 32
00146   *            @arg TIM4_Prescaler_64: Time base Prescaler = 64
00147   *            @arg TIM4_Prescaler_128: Time base Prescaler = 128
00148   *            @arg TIM4_Prescaler_256: Time base Prescaler = 256
00149   *            @arg TIM4_Prescaler_512: Time base Prescaler = 512
00150   *            @arg TIM4_Prescaler_1024: Time base Prescaler = 1024
00151   *            @arg TIM4_Prescaler_2048: Time base Prescaler = 2048
00152   *            @arg TIM4_Prescaler_4096: Time base Prescaler = 4096
00153   *            @arg TIM4_Prescaler_8192: Time base Prescaler = 8192
00154   *            @arg TIM4_Prescaler_16384: Time base Prescaler = 16384
00155   *            @arg TIM4_Prescaler_32768: Time base Prescaler = 32768                              
00156   * @param  TIM4_Period: This parameter must be a value between 0x00 and 0xFF.
00157   * @retval None
00158   */
00159 void TIM4_TimeBaseInit(TIM4_Prescaler_TypeDef TIM4_Prescaler,
00160                        uint8_t TIM4_Period)
00161 {
00162   /* Check TIM4 prescaler value */
00163   assert_param(IS_TIM4_Prescaler(TIM4_Prescaler));
00164   /* Set the Autoreload value */
00165   TIM4->ARR = (uint8_t)(TIM4_Period);
00166   /* Set the Prescaler value */
00167   TIM4->PSCR = (uint8_t)(TIM4_Prescaler);
00168 
00169   /* Generate an update event to reload the Prescaler value immediately */
00170   TIM4->EGR = TIM4_EventSource_Update;
00171 }
00172 
00173 /**
00174   * @brief  Configures the TIM4 Prescaler.
00175   * @param  Prescaler: Specifies the Prescaler Register value
00176   *          This parameter can be one of the following values:
00177   *            @arg TIM4_Prescaler_1: Time base Prescaler = 1 (No effect)
00178   *            @arg TIM4_Prescaler_2: Time base Prescaler = 2
00179   *            @arg TIM4_Prescaler_4: Time base Prescaler = 4
00180   *            @arg TIM4_Prescaler_8: Time base Prescaler = 8
00181   *            @arg TIM4_Prescaler_16: Time base Prescaler = 16
00182   *            @arg TIM4_Prescaler_32: Time base Prescaler = 32
00183   *            @arg TIM4_Prescaler_64: Time base Prescaler = 64
00184   *            @arg TIM4_Prescaler_128: Time base Prescaler = 128
00185   *            @arg TIM4_Prescaler_256: Time base Prescaler = 256
00186   *            @arg TIM4_Prescaler_512: Time base Prescaler = 512
00187   *            @arg TIM4_Prescaler_1024: Time base Prescaler = 1024
00188   *            @arg TIM4_Prescaler_2048: Time base Prescaler = 2048
00189   *            @arg TIM4_Prescaler_4096: Time base Prescaler = 4096
00190   *            @arg TIM4_Prescaler_8192: Time base Prescaler = 8192
00191   *            @arg TIM4_Prescaler_16384: Time base Prescaler = 16384
00192   *            @arg TIM4_Prescaler_32768: Time base Prescaler = 32768 
00193   * @param  TIM4_PSCReloadMode: Specifies the TIM4 Prescaler Reload mode.
00194   *          This parameter can be one of the following values:
00195   *            @arg TIM4_PSCReloadMode_Update: Prescaler value is reloaded at every update
00196   *            @arg TIM4_PSCReloadMode_Immediate: Prescaler value is reloaded immediatly
00197   * @retval None
00198   */
00199 void TIM4_PrescalerConfig(TIM4_Prescaler_TypeDef Prescaler,
00200                           TIM4_PSCReloadMode_TypeDef TIM4_PSCReloadMode)
00201 {
00202   /* Check the parameters */
00203   assert_param(IS_TIM4_Prescaler_RELOAD(TIM4_PSCReloadMode));
00204   assert_param(IS_TIM4_Prescaler(Prescaler));
00205 
00206   /* Set the Prescaler value */
00207   TIM4->PSCR = (uint8_t) Prescaler;
00208 
00209   /* Set or reset the UG Bit */
00210   if (TIM4_PSCReloadMode == TIM4_PSCReloadMode_Immediate)
00211   {
00212     TIM4->EGR |= TIM4_EGR_UG ;
00213   }
00214   else
00215   {
00216     TIM4->EGR &= (uint8_t)(~TIM4_EGR_UG) ;
00217   }
00218 }
00219 
00220 /**
00221   * @brief  Sets the TIM4 Counter Register value.
00222   * @param  Counter: Specifies the Counter register new value.
00223   *          This parameter is between 0x00 and 0xFF.
00224   * @retval None
00225   */
00226 void TIM4_SetCounter(uint8_t Counter)
00227 {
00228   /* Set the Counter Register value */
00229   TIM4->CNTR = (uint8_t)(Counter);
00230 }
00231 
00232 /**
00233   * @brief  Sets the TIM4 Autoreload Register value.
00234   * @param  Autoreload: Specifies the Autoreload register new value.
00235   *          This parameter is between 0x00 and 0xFF.
00236   * @retval None
00237   */
00238 void TIM4_SetAutoreload(uint8_t Autoreload)
00239 {
00240   /* Set the Autoreload Register value */
00241   TIM4->ARR = (uint8_t)(Autoreload);
00242 }
00243 
00244 /**
00245   * @brief  Gets the TIM4 Counter value.
00246   * @param  None
00247   * @retval Counter Register value.
00248   */
00249 uint8_t TIM4_GetCounter(void)
00250 {
00251   uint8_t tmpcntr = 0;
00252   tmpcntr = TIM4->CNTR;
00253   /* Get the Counter Register value */
00254   return ((uint8_t)tmpcntr);
00255 }
00256 
00257 /**
00258   * @brief  Gets the TIM4 Prescaler value.
00259   * @param  None
00260   * @retval TIM4 Prescaler can be one of the following values:
00261   *            - TIM4_Prescaler_1: Time base Prescaler = 1 (No effect)
00262   *            - TIM4_Prescaler_2: Time base Prescaler = 2
00263   *            - TIM4_Prescaler_4: Time base Prescaler = 4
00264   *            - TIM4_Prescaler_8: Time base Prescaler = 8
00265   *            - TIM4_Prescaler_16: Time base Prescaler = 16
00266   *            - TIM4_Prescaler_32: Time base Prescaler = 32
00267   *            - TIM4_Prescaler_64: Time base Prescaler = 64
00268   *            - TIM4_Prescaler_128: Time base Prescaler = 128
00269   *            - TIM4_Prescaler_256: Time base Prescaler = 256
00270   *            - TIM4_Prescaler_512: Time base Prescaler = 512
00271   *            - TIM4_Prescaler_1024: Time base Prescaler = 1024
00272   *            - TIM4_Prescaler_2048: Time base Prescaler = 2048
00273   *            - TIM4_Prescaler_4096: Time base Prescaler = 4096
00274   *            - TIM4_Prescaler_8192: Time base Prescaler = 8192
00275   *            - TIM4_Prescaler_16384: Time base Prescaler = 16384
00276   *            - TIM4_Prescaler_32768: Time base Prescaler = 32768  
00277   */
00278 TIM4_Prescaler_TypeDef TIM4_GetPrescaler(void)
00279 {
00280   /* Get the Prescaler Register value */
00281   return ((TIM4_Prescaler_TypeDef)TIM4->PSCR);
00282 }
00283 
00284 /**
00285   * @brief  Enables or Disables the TIM4 Update event.
00286   * @param  NewState: The new state of the TIM4 peripheral Preload register.
00287   *          This parameter can be ENABLE or DISABLE
00288   * @retval None
00289   */
00290 void TIM4_UpdateDisableConfig(FunctionalState NewState)
00291 {
00292   /* Check the parameters */
00293   assert_param(IS_FUNCTIONAL_STATE(NewState));
00294 
00295   /* Set or Reset the UDIS Bit */
00296   if (NewState != DISABLE)
00297   {
00298     TIM4->CR1 |= TIM4_CR1_UDIS ;
00299   }
00300   else
00301   {
00302     TIM4->CR1 &= (uint8_t)(~TIM4_CR1_UDIS) ;
00303   }
00304 }
00305 
00306 /**
00307   * @brief  Selects the TIM4 Update Request Interrupt source.
00308   * @param  TIM4_UpdateSource: Specifies the Update source.
00309   *          This parameter can be one of the following values:
00310   *            @arg TIM4_UpdateSource_Global: Global Update request source
00311   *            @arg TIM4_UpdateSource_Regular: Regular Update request source
00312   * @retval None
00313   */
00314 void TIM4_UpdateRequestConfig(TIM4_UpdateSource_TypeDef TIM4_UpdateSource)
00315 {
00316   /* Check the parameters */
00317   assert_param(IS_TIM4_UPDATE_SOURCE(TIM4_UpdateSource));
00318 
00319   /* Set or Reset the URS Bit */
00320   if (TIM4_UpdateSource == TIM4_UpdateSource_Regular)
00321   {
00322     TIM4->CR1 |= TIM4_CR1_URS ;
00323   }
00324   else
00325   {
00326     TIM4->CR1 &= (uint8_t)(~TIM4_CR1_URS) ;
00327   }
00328 }
00329 
00330 /**
00331   * @brief  Enables or disables TIM4 peripheral Preload register on ARR.
00332   * @param  NewState: The new state of the TIM4 peripheral Preload register.
00333   *          This parameter can be ENABLE or DISABLE
00334   * @retval None
00335   */
00336 void TIM4_ARRPreloadConfig(FunctionalState NewState)
00337 {
00338   /* Check the parameters */
00339   assert_param(IS_FUNCTIONAL_STATE(NewState));
00340 
00341   /* Set or Reset the ARPE Bit */
00342   if (NewState != DISABLE)
00343   {
00344     TIM4->CR1 |= TIM4_CR1_ARPE ;
00345   }
00346   else
00347   {
00348     TIM4->CR1 &= (uint8_t)(~TIM4_CR1_ARPE) ;
00349   }
00350 }
00351 
00352 /**
00353   * @brief  Selects the TIM4�s One Pulse Mode.
00354   * @param  TIM4_OPMode: Specifies the OPM Mode to be used.
00355   *          This parameter can be one of the following values:
00356   *            @arg TIM4_OPMode_Single: Single one Pulse mode (OPM Active)
00357   *            @arg TIM4_OPMode_Repetitive: Repetitive Pulse mode (OPM inactive)
00358   * @retval None
00359   */
00360 void TIM4_SelectOnePulseMode(TIM4_OPMode_TypeDef TIM4_OPMode)
00361 {
00362   /* Check the parameters */
00363   assert_param(IS_TIM4_OPM_MODE(TIM4_OPMode));
00364 
00365   /* Set or Reset the OPM Bit */
00366   if (TIM4_OPMode == TIM4_OPMode_Single)
00367   {
00368     TIM4->CR1 |= TIM4_CR1_OPM ;
00369   }
00370   else
00371   {
00372     TIM4->CR1 &= (uint8_t)(~TIM4_CR1_OPM) ;
00373   }
00374 }
00375 
00376 /**
00377   * @brief  Enables or disables the TIM4 peripheral.
00378   * @param  NewState: The new state of the TIM4 peripheral.
00379   *          This parameter can be ENABLE or DISABLE
00380   * @retval None
00381   */
00382 void TIM4_Cmd(FunctionalState NewState)
00383 {
00384   /* Check the parameters */
00385   assert_param(IS_FUNCTIONAL_STATE(NewState));
00386 
00387   /* set or Reset the CEN Bit */
00388   if (NewState != DISABLE)
00389   {
00390     TIM4->CR1 |= TIM4_CR1_CEN ;
00391   }
00392   else
00393   {
00394     TIM4->CR1 &= (uint8_t)(~TIM4_CR1_CEN) ;
00395   }
00396 }
00397 
00398 /**
00399   * @}
00400   */
00401 
00402 /** @defgroup TIM4_Group2 Interrupts DMA and flags management functions
00403  *  @brief    Interrupts, DMA and flags management functions 
00404  *
00405 @verbatim   
00406  ===============================================================================
00407                  Interrupts, DMA and flags management functions
00408  ===============================================================================  
00409 
00410 @endverbatim
00411   * @{
00412   */
00413 
00414 /**
00415   * @brief  Enables or disables the specified TIM4 interrupts.
00416   * @param  TIM4_IT: Specifies the TIM4 interrupts sources to be enabled or disabled.
00417   *          This parameter can be one of the following values:
00418   *            @arg TIM4_IT_Update: Update
00419   *            @arg TIM4_IT_Trigger: Trigger
00420   * @param  NewState: The new state of the TIM4 peripheral.
00421   *          This parameter can be ENABLE or DISABLE
00422   * @retval None
00423   */
00424 void TIM4_ITConfig(TIM4_IT_TypeDef TIM4_IT, FunctionalState NewState)
00425 {
00426   /* Check the parameters */
00427   assert_param(IS_TIM4_IT(TIM4_IT));
00428   assert_param(IS_FUNCTIONAL_STATE(NewState));
00429 
00430   if (NewState != DISABLE)
00431   {
00432     /* Enable the Interrupt sources */
00433     TIM4->IER |= (uint8_t)TIM4_IT;
00434   }
00435   else
00436   {
00437     /* Disable the Interrupt sources */
00438     TIM4->IER &= (uint8_t)(~(uint8_t)TIM4_IT);
00439   }
00440 }
00441 
00442 /**
00443   * @brief  Configures the TIM4 event to be generated by software.
00444   * @param  TIM4_EventSource: Specifies the event source.
00445   *          This parameter can be one of the following values:
00446   *            @arg TIM4_EventSource_Update: Update
00447   *            @arg TIM4_EventSource_Trigger: Trigger
00448   * @retval None
00449   */
00450 void TIM4_GenerateEvent(TIM4_EventSource_TypeDef TIM4_EventSource)
00451 {
00452   /* Check the parameters */
00453   assert_param(IS_TIM4_EVENT_SOURCE((uint8_t)TIM4_EventSource));
00454 
00455   /* Set the event sources */
00456   TIM4->EGR |= (uint8_t)TIM4_EventSource;
00457 }
00458 
00459 /**
00460   * @brief  Checks whether the specified TIM4 flag is set or not.
00461   * @param  TIM4_FLAG: Specifies the flag to check.
00462   *          This parameter can be one of the following values:
00463   *            @arg TIM4_FLAG_Update: Update
00464   *            @arg TIM4_FLAG_Trigger: Trigger
00465   * @retval FlagStatus: The new state of TIM4_FLAG.
00466   *          This parameter can be SET or RESET.
00467   */
00468 FlagStatus TIM4_GetFlagStatus(TIM4_FLAG_TypeDef TIM4_FLAG)
00469 {
00470   FlagStatus bitstatus = RESET;
00471 
00472   /* Check the parameters */
00473   assert_param(IS_TIM4_GET_FLAG(TIM4_FLAG));
00474 
00475   if ((TIM4->SR1 & (uint8_t)TIM4_FLAG)  != 0)
00476   {
00477     bitstatus = SET;
00478   }
00479   else
00480   {
00481     bitstatus = RESET;
00482   }
00483   return ((FlagStatus)bitstatus);
00484 }
00485 
00486 /**
00487   * @brief  Clears the TIM�s pending flags.
00488   * @param  TIM4_FLAG: Specifies the flag to clear.
00489   *          This parameter can be one of the following values:
00490   *            @arg TIM4_FLAG_Update: Update
00491   *            @arg TIM4_FLAG_Trigger: Trigger
00492   * @retval None
00493   */
00494 void TIM4_ClearFlag(TIM4_FLAG_TypeDef TIM4_FLAG)
00495 {
00496   /* Check the parameters */
00497   assert_param(IS_TIM4_CLEAR_FLAG((uint8_t)TIM4_FLAG));
00498   /* Clear the flags (rc_w0) clear this bit by writing 0. Writing �1� has no effect*/
00499   TIM4->SR1 = (uint8_t)(~((uint8_t)TIM4_FLAG));
00500 }
00501 
00502 /**
00503   * @brief  Checks whether the TIM4 interrupt has occurred or not.
00504   * @param  TIM4_IT: Specifies the TIM4 interrupt source to check.
00505   *          This parameter can be one of the following values:
00506   *            @arg TIM4_IT_Update: Update
00507   *            @arg TIM4_IT_Trigger: Trigger
00508   * @retval ITStatus: The new state of the TIM4_IT.
00509   *          This parameter can be SET or RESET
00510   */
00511 
00512 ITStatus TIM4_GetITStatus(TIM4_IT_TypeDef TIM4_IT)
00513 {
00514   ITStatus bitstatus = RESET;
00515 
00516   uint8_t itStatus = 0x0, itEnable = 0x0;
00517 
00518   /* Check the parameters */
00519   assert_param(IS_TIM4_GET_IT(TIM4_IT));
00520 
00521   itStatus = (uint8_t)(TIM4->SR1 & (uint8_t)TIM4_IT);
00522 
00523   itEnable = (uint8_t)(TIM4->IER & (uint8_t)TIM4_IT);
00524 
00525   if ((itStatus != (uint8_t)RESET ) && (itEnable != (uint8_t)RESET ))
00526   {
00527     bitstatus = (ITStatus)SET;
00528   }
00529   else
00530   {
00531     bitstatus = (ITStatus)RESET;
00532   }
00533   return ((ITStatus)bitstatus);
00534 }
00535 
00536 /**
00537   * @brief  Clears the TIM4's interrupt pending bits.
00538   * @param  TIM4_IT: Specifies the pending bit to clear.
00539   *          This parameter can be one of the following values:
00540   *            @arg TIM4_IT_Update: Update
00541   *            @arg TIM4_IT_Trigger: Trigger
00542   * @retval None
00543   */
00544 void TIM4_ClearITPendingBit(TIM4_IT_TypeDef TIM4_IT)
00545 {
00546   /* Check the parameters */
00547   assert_param(IS_TIM4_IT(TIM4_IT));
00548 
00549   /* Clear the IT pending Bit */
00550   TIM4->SR1 = (uint8_t)(~(uint8_t)TIM4_IT);
00551 }
00552 
00553 /**
00554   * @brief  Enables or disables the TIMx�s DMA Requests.
00555   * @param  TIM4_DMASources: specifies the DMA Request sources.
00556   *          This parameter can be one of the following values:
00557   *            @arg TIM4_DMASource_Update: Update
00558   * @param  NewState: new state of the DMA Request sources.
00559   *          This parameter can be: ENABLE or DISABLE.
00560   * @retval None
00561   */
00562 void TIM4_DMACmd( TIM4_DMASource_TypeDef TIM4_DMASource, FunctionalState NewState)
00563 {
00564   /* Check the parameters */
00565   assert_param(IS_FUNCTIONAL_STATE(NewState));
00566   assert_param(IS_TIM4_DMA_SOURCE(TIM4_DMASource));
00567 
00568   if (NewState != DISABLE)
00569   {
00570     /* Enable the DMA sources */
00571     TIM4->DER |= (uint8_t)TIM4_DMASource;
00572   }
00573   else
00574   {
00575     /* Disable the DMA sources */
00576     TIM4->DER &= (uint8_t)~TIM4_DMASource;
00577   }
00578 }
00579 
00580 /**
00581   * @}
00582   */
00583 
00584 /** @defgroup TIM4_Group3 Clocks management functions
00585  *  @brief    Clocks management functions
00586  *
00587 @verbatim   
00588  ===============================================================================
00589                          Clocks management functions
00590  ===============================================================================  
00591 
00592 @endverbatim
00593   * @{
00594   */
00595 
00596 /**
00597   * @brief  Enables the TIM4 internal Clock.
00598   * @param  None
00599   * @retval None
00600   */
00601 void TIM4_InternalClockConfig(void)
00602 {
00603   /* Disable slave mode to clock the prescaler directly with the internal clock */
00604   TIM4->SMCR &=  (uint8_t)(~TIM4_SMCR_SMS);
00605 }
00606 
00607 /**
00608   * @}
00609   */
00610 
00611 /** @defgroup TIM4_Group4 Synchronization management functions
00612  *  @brief    Synchronization management functions 
00613  *
00614 @verbatim   
00615  ===============================================================================
00616                        Synchronization management functions
00617  ===============================================================================  
00618                    
00619        ===================================================================      
00620               TIM4 Driver: how to use it in synchronization Mode
00621        =================================================================== 
00622        Case of two/several Timers
00623        **************************
00624        1. If TIM4 is used as master to other timers use the following functions:
00625           - TIM4_SelectOutputTrigger()
00626           - TIM4_SelectMasterSlaveMode()
00627        2. If TIM4 is used as slave to other timers use the following functions:
00628           - TIM4_SelectInputTrigger()
00629           - TIM4_SelectSlaveMode()
00630           
00631 @endverbatim
00632   * @{
00633   */
00634 
00635 /**
00636   * @brief  Selects the TIM4 Input Trigger source.
00637   * @param  TIM4_InputTriggerSource: Specifies Input Trigger source.
00638   *          This parameter can be one of the following values:
00639   *            @arg TIM4_TRGSelection_TIM5: TRIG Input source =  TIM5 TRIG Output
00640   *            @arg TIM4_TRGSelection_TIM1: TRIG Input source =  TIM1 TRIG Output
00641   *            @arg TIM4_TRGSelection_TIM3: TRIG Input source =  TIM3 TRIG Output
00642   *            @arg TIM4_TRGSelection_TIM2: TRIG Input source =  TIM2 TRIG Output
00643   * @retval None
00644   */
00645 void TIM4_SelectInputTrigger(TIM4_TRGSelection_TypeDef TIM4_InputTriggerSource)
00646 {
00647   uint8_t tmpsmcr = 0;
00648 
00649   /* Check the parameters */
00650   assert_param(IS_TIM4_TRIGGER_SELECTION(TIM4_InputTriggerSource));
00651 
00652   tmpsmcr = TIM4->SMCR;
00653 
00654   /* Select the Trigger Source */
00655   tmpsmcr &= (uint8_t)(~TIM4_SMCR_TS);
00656   tmpsmcr |= (uint8_t)TIM4_InputTriggerSource;
00657 
00658   TIM4->SMCR = (uint8_t)tmpsmcr;
00659 }
00660 
00661 /**
00662   * @brief  Selects the TIM4 Trigger Output Mode.
00663   * @param  TIM4_TRGOSource: Specifies the Trigger Output source.
00664   *          This parameter can be one of the following values:
00665   *            @arg TIM4_TRGOSource_Reset: Trigger Output source = Reset
00666   *            @arg TIM4_TRGOSource_Enable: Trigger Output source = TIM4 is enabled
00667   *            @arg TIM4_TRGOSource_Update: Trigger Output source = Update event
00668   * @retval None
00669   */
00670 void TIM4_SelectOutputTrigger(TIM4_TRGOSource_TypeDef TIM4_TRGOSource)
00671 {
00672   uint8_t tmpcr2 = 0;
00673 
00674   /* Check the parameters */
00675   assert_param(IS_TIM4_TRGO_SOURCE(TIM4_TRGOSource));
00676 
00677   tmpcr2 = TIM4->CR2;
00678 
00679   /* Reset the MMS Bits */
00680   tmpcr2 &= (uint8_t)(~TIM4_CR2_MMS);
00681 
00682   /* Select the TRGO source */
00683   tmpcr2 |=  (uint8_t)TIM4_TRGOSource;
00684 
00685   TIM4->CR2 = tmpcr2;
00686 }
00687 
00688 /**
00689   * @brief  Selects the TIM4 Slave Mode.
00690   * @param  TIM4_SlaveMode: Specifies the TIM4 Slave Mode.
00691   *          This parameter can be one of the following values:
00692   *            @arg TIM4_SlaveMode_Disable: Disable slave mode to clock the prescaler
00693                                             directly with the internal clock
00694   *            @arg TIM4_SlaveMode_Reset: Slave Mode Selection  = Reset
00695   *            @arg TIM4_SlaveMode_Gated: Slave Mode Selection  = Gated
00696   *            @arg TIM4_SlaveMode_Trigger: Slave Mode Selection  = Trigger
00697   *            @arg TIM4_SlaveMode_External1: Slave Mode Selection  = External 1  
00698   * @retval None
00699   */
00700 void TIM4_SelectSlaveMode(TIM4_SlaveMode_TypeDef TIM4_SlaveMode)
00701 {
00702   uint8_t tmpsmcr = 0;
00703 
00704   /* Check the parameters */
00705   assert_param(IS_TIM4_SLAVE_MODE(TIM4_SlaveMode));
00706 
00707   tmpsmcr = TIM4->SMCR;
00708 
00709   /* Reset the SMS Bits */
00710   tmpsmcr &= (uint8_t)(~TIM4_SMCR_SMS);
00711 
00712   /* Select the Slave Mode */
00713   tmpsmcr |= (uint8_t)TIM4_SlaveMode;
00714 
00715   TIM4->SMCR = tmpsmcr;
00716 }
00717 
00718 /**
00719   * @brief  Sets or Resets the TIM4 Master/Slave Mode.
00720   * @param NewState: The new state of the synchronization between TIM4 and its slaves (through TRGO).
00721   *          This parameter can be ENABLE or DISABLE
00722   * @retval None
00723   */
00724 void TIM4_SelectMasterSlaveMode(FunctionalState NewState)
00725 {
00726   /* Check the parameters */
00727   assert_param(IS_FUNCTIONAL_STATE(NewState));
00728 
00729   /* Set or Reset the MSM Bit */
00730   if (NewState != DISABLE)
00731   {
00732     TIM4->SMCR |= TIM4_SMCR_MSM;
00733   }
00734   else
00735   {
00736     TIM4->SMCR &= (uint8_t)(~TIM4_SMCR_MSM);
00737   }
00738 }
00739 
00740 /**
00741   * @}
00742   */ 
00743 
00744 /**
00745   * @}
00746   */ 
00747   
00748 /**
00749   * @}
00750   */
00751 
00752 /**
00753   * @}
00754   */
00755 
00756 /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
STM8S Firmware Library: Overview

 

 

 

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