STM8S/A Standard Peripherals Drivers: stm8s_tim3.c Source File

STM8S/A

stm8s_tim3.c
Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    stm8s_tim3.c
00004   * @author  MCD Application Team
00005   * @version V2.3.0
00006   * @date    16-June-2017
00007   * @brief   This file contains all the functions for the TIM3 peripheral.
00008    ******************************************************************************
00009   * @attention
00010   *
00011   * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
00012   *
00013   * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
00014   * You may not use this file except in compliance with the License.
00015   * You may obtain a copy of the License at:
00016   *
00017   *        http://www.st.com/software_license_agreement_liberty_v2
00018   *
00019   * Unless required by applicable law or agreed to in writing, software 
00020   * distributed under the License is distributed on an "AS IS" BASIS, 
00021   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00022   * See the License for the specific language governing permissions and
00023   * limitations under the License.
00024   *
00025   ******************************************************************************
00026   */
00027 
00028 /* Includes ------------------------------------------------------------------*/
00029 #include "stm8s_tim3.h"
00030 
00031 /** @addtogroup STM8S_StdPeriph_Driver
00032   * @{
00033   */
00034 /* Private typedef -----------------------------------------------------------*/
00035 /* Private define ------------------------------------------------------------*/
00036 /* Private macro -------------------------------------------------------------*/
00037 /* Private variables ---------------------------------------------------------*/
00038 /* Private function prototypes -----------------------------------------------*/
00039 static void TI1_Config(uint8_t TIM3_ICPolarity, uint8_t TIM3_ICSelection, uint8_t TIM3_ICFilter);
00040 static void TI2_Config(uint8_t TIM3_ICPolarity, uint8_t TIM3_ICSelection, uint8_t TIM3_ICFilter);
00041 /**
00042   * @addtogroup TIM3_Public_Functions
00043   * @{
00044   */
00045 
00046 /**
00047   * @brief  Deinitializes the TIM3 peripheral registers to their default reset values.
00048   * @param  None
00049   * @retval None
00050   */
00051 void TIM3_DeInit(void)
00052 {
00053   TIM3->CR1 = (uint8_t)TIM3_CR1_RESET_VALUE;
00054   TIM3->IER = (uint8_t)TIM3_IER_RESET_VALUE;
00055   TIM3->SR2 = (uint8_t)TIM3_SR2_RESET_VALUE;
00056   
00057   /* Disable channels */
00058   TIM3->CCER1 = (uint8_t)TIM3_CCER1_RESET_VALUE;
00059   
00060   /* Then reset channel registers: it also works if lock level is equal to 2 or 3 */
00061   TIM3->CCER1 = (uint8_t)TIM3_CCER1_RESET_VALUE;
00062   TIM3->CCMR1 = (uint8_t)TIM3_CCMR1_RESET_VALUE;
00063   TIM3->CCMR2 = (uint8_t)TIM3_CCMR2_RESET_VALUE;
00064   TIM3->CNTRH = (uint8_t)TIM3_CNTRH_RESET_VALUE;
00065   TIM3->CNTRL = (uint8_t)TIM3_CNTRL_RESET_VALUE;
00066   TIM3->PSCR = (uint8_t)TIM3_PSCR_RESET_VALUE;
00067   TIM3->ARRH  = (uint8_t)TIM3_ARRH_RESET_VALUE;
00068   TIM3->ARRL  = (uint8_t)TIM3_ARRL_RESET_VALUE;
00069   TIM3->CCR1H = (uint8_t)TIM3_CCR1H_RESET_VALUE;
00070   TIM3->CCR1L = (uint8_t)TIM3_CCR1L_RESET_VALUE;
00071   TIM3->CCR2H = (uint8_t)TIM3_CCR2H_RESET_VALUE;
00072   TIM3->CCR2L = (uint8_t)TIM3_CCR2L_RESET_VALUE;
00073   TIM3->SR1 = (uint8_t)TIM3_SR1_RESET_VALUE;
00074 }
00075 
00076 /**
00077   * @brief  Initializes the TIM3 Time Base Unit according to the specified parameters.
00078   * @param    TIM3_Prescaler specifies the Prescaler from TIM3_Prescaler_TypeDef.
00079   * @param    TIM3_Period specifies the Period value.
00080   * @retval None
00081   */
00082 void TIM3_TimeBaseInit( TIM3_Prescaler_TypeDef TIM3_Prescaler,
00083                         uint16_t TIM3_Period)
00084 {
00085   /* Set the Prescaler value */
00086   TIM3->PSCR = (uint8_t)(TIM3_Prescaler);
00087   /* Set the Autoreload value */
00088   TIM3->ARRH = (uint8_t)(TIM3_Period >> 8);
00089   TIM3->ARRL = (uint8_t)(TIM3_Period);
00090 }
00091 
00092 /**
00093   * @brief  Initializes the TIM3 Channel1 according to the specified parameters.
00094   * @param   TIM3_OCMode specifies the Output Compare mode  from @ref TIM3_OCMode_TypeDef.
00095   * @param   TIM3_OutputState specifies the Output State  from @ref TIM3_OutputState_TypeDef.
00096   * @param   TIM3_Pulse specifies the Pulse width  value.
00097   * @param   TIM3_OCPolarity specifies the Output Compare Polarity  from @ref TIM3_OCPolarity_TypeDef.
00098   * @retval None
00099   */
00100 void TIM3_OC1Init(TIM3_OCMode_TypeDef TIM3_OCMode,
00101                   TIM3_OutputState_TypeDef TIM3_OutputState,
00102                   uint16_t TIM3_Pulse,
00103                   TIM3_OCPolarity_TypeDef TIM3_OCPolarity)
00104 {
00105   /* Check the parameters */
00106   assert_param(IS_TIM3_OC_MODE_OK(TIM3_OCMode));
00107   assert_param(IS_TIM3_OUTPUT_STATE_OK(TIM3_OutputState));
00108   assert_param(IS_TIM3_OC_POLARITY_OK(TIM3_OCPolarity));
00109   
00110   /* Disable the Channel 1: Reset the CCE Bit, Set the Output State , the Output Polarity */
00111   TIM3->CCER1 &= (uint8_t)(~( TIM3_CCER1_CC1E | TIM3_CCER1_CC1P));
00112   /* Set the Output State &  Set the Output Polarity  */
00113   TIM3->CCER1 |= (uint8_t)((uint8_t)(TIM3_OutputState  & TIM3_CCER1_CC1E   ) | (uint8_t)(TIM3_OCPolarity   & TIM3_CCER1_CC1P   ));
00114   
00115   /* Reset the Output Compare Bits & Set the Output Compare Mode */
00116   TIM3->CCMR1 = (uint8_t)((uint8_t)(TIM3->CCMR1 & (uint8_t)(~TIM3_CCMR_OCM)) | (uint8_t)TIM3_OCMode);
00117   
00118   /* Set the Pulse value */
00119   TIM3->CCR1H = (uint8_t)(TIM3_Pulse >> 8);
00120   TIM3->CCR1L = (uint8_t)(TIM3_Pulse);
00121 }
00122 
00123 /**
00124   * @brief  Initializes the TIM3 Channel2 according to the specified parameters.
00125   * @param   TIM3_OCMode specifies the Output Compare mode  from @ref TIM3_OCMode_TypeDef.
00126   * @param   TIM3_OutputState specifies the Output State  from @ref TIM3_OutputState_TypeDef.
00127   * @param   TIM3_Pulse specifies the Pulse width  value.
00128   * @param   TIM3_OCPolarity specifies the Output Compare Polarity  from @ref TIM3_OCPolarity_TypeDef.
00129   * @retval None
00130   */
00131 void TIM3_OC2Init(TIM3_OCMode_TypeDef TIM3_OCMode,
00132                   TIM3_OutputState_TypeDef TIM3_OutputState,
00133                   uint16_t TIM3_Pulse,
00134                   TIM3_OCPolarity_TypeDef TIM3_OCPolarity)
00135 {
00136   /* Check the parameters */
00137   assert_param(IS_TIM3_OC_MODE_OK(TIM3_OCMode));
00138   assert_param(IS_TIM3_OUTPUT_STATE_OK(TIM3_OutputState));
00139   assert_param(IS_TIM3_OC_POLARITY_OK(TIM3_OCPolarity));
00140   
00141   
00142   /* Disable the Channel 1: Reset the CCE Bit, Set the Output State, the Output Polarity */
00143   TIM3->CCER1 &= (uint8_t)(~( TIM3_CCER1_CC2E |  TIM3_CCER1_CC2P ));
00144   /* Set the Output State & Set the Output Polarity */
00145   TIM3->CCER1 |= (uint8_t)((uint8_t)(TIM3_OutputState  & TIM3_CCER1_CC2E   ) | (uint8_t)(TIM3_OCPolarity   & TIM3_CCER1_CC2P ));
00146   
00147   
00148   /* Reset the Output Compare Bits & Set the Output Compare Mode */
00149   TIM3->CCMR2 = (uint8_t)((uint8_t)(TIM3->CCMR2 & (uint8_t)(~TIM3_CCMR_OCM)) | (uint8_t)TIM3_OCMode);
00150   
00151   
00152   /* Set the Pulse value */
00153   TIM3->CCR2H = (uint8_t)(TIM3_Pulse >> 8);
00154   TIM3->CCR2L = (uint8_t)(TIM3_Pulse);
00155 }
00156 
00157 /**
00158   * @brief  Initializes the TIM3 peripheral according to the specified parameters.
00159   * @param    TIM3_Channel specifies the Input Capture Channel from @ref TIM3_Channel_TypeDef.
00160   * @param   TIM3_ICPolarity specifies the Input Capture Polarity from @ref TIM3_ICPolarity_TypeDef.
00161   * @param   TIM3_ICSelection specifies the Input Capture Selection from @ref TIM3_ICSelection_TypeDef.
00162   * @param   TIM3_ICPrescaler specifies the Input Capture Prescaler from @ref TIM3_ICPSC_TypeDef.
00163   * @param   TIM3_ICFilter specifies the Input Capture Filter value (value can be an integer from 0x00 to 0x0F).
00164   * @retval None
00165   */
00166 void TIM3_ICInit(TIM3_Channel_TypeDef TIM3_Channel,
00167                  TIM3_ICPolarity_TypeDef TIM3_ICPolarity,
00168                  TIM3_ICSelection_TypeDef TIM3_ICSelection,
00169                  TIM3_ICPSC_TypeDef TIM3_ICPrescaler,
00170                  uint8_t TIM3_ICFilter)
00171 {
00172   /* Check the parameters */
00173   assert_param(IS_TIM3_CHANNEL_OK(TIM3_Channel));
00174   assert_param(IS_TIM3_IC_POLARITY_OK(TIM3_ICPolarity));
00175   assert_param(IS_TIM3_IC_SELECTION_OK(TIM3_ICSelection));
00176   assert_param(IS_TIM3_IC_PRESCALER_OK(TIM3_ICPrescaler));
00177   assert_param(IS_TIM3_IC_FILTER_OK(TIM3_ICFilter));
00178   
00179   if (TIM3_Channel != TIM3_CHANNEL_2)
00180   {
00181     /* TI1 Configuration */
00182     TI1_Config((uint8_t)TIM3_ICPolarity,
00183                (uint8_t)TIM3_ICSelection,
00184                (uint8_t)TIM3_ICFilter);
00185     
00186     /* Set the Input Capture Prescaler value */
00187     TIM3_SetIC1Prescaler(TIM3_ICPrescaler);
00188   }
00189   else
00190   {
00191     /* TI2 Configuration */
00192     TI2_Config((uint8_t)TIM3_ICPolarity,
00193                (uint8_t)TIM3_ICSelection,
00194                (uint8_t)TIM3_ICFilter);
00195     
00196     /* Set the Input Capture Prescaler value */
00197     TIM3_SetIC2Prescaler(TIM3_ICPrescaler);
00198   }
00199 }
00200 
00201 /**
00202   * @brief  Configures the TIM3 peripheral in PWM Input Mode according to the specified parameters.
00203   * @param    TIM3_Channel specifies the Input Capture Channel from @ref TIM3_Channel_TypeDef.
00204   * @param   TIM3_ICPolarity specifies the Input Capture Polarity from @ref TIM3_ICPolarity_TypeDef.
00205   * @param   TIM3_ICSelection specifies the Input Capture Selection from @ref TIM3_ICSelection_TypeDef.
00206   * @param   TIM3_ICPrescaler specifies the Input Capture Prescaler from @ref TIM3_ICPSC_TypeDef.
00207   * @param   TIM3_ICFilter specifies the Input Capture Filter value (value can be an integer from 0x00 to 0x0F).
00208   * @retval None
00209   */
00210 void TIM3_PWMIConfig(TIM3_Channel_TypeDef TIM3_Channel,
00211                      TIM3_ICPolarity_TypeDef TIM3_ICPolarity,
00212                      TIM3_ICSelection_TypeDef TIM3_ICSelection,
00213                      TIM3_ICPSC_TypeDef TIM3_ICPrescaler,
00214                      uint8_t TIM3_ICFilter)
00215 {
00216   uint8_t icpolarity = (uint8_t)TIM3_ICPOLARITY_RISING;
00217   uint8_t icselection = (uint8_t)TIM3_ICSELECTION_DIRECTTI;
00218   
00219   /* Check the parameters */
00220   assert_param(IS_TIM3_PWMI_CHANNEL_OK(TIM3_Channel));
00221   assert_param(IS_TIM3_IC_POLARITY_OK(TIM3_ICPolarity));
00222   assert_param(IS_TIM3_IC_SELECTION_OK(TIM3_ICSelection));
00223   assert_param(IS_TIM3_IC_PRESCALER_OK(TIM3_ICPrescaler));
00224   
00225   /* Select the Opposite Input Polarity */
00226   if (TIM3_ICPolarity != TIM3_ICPOLARITY_FALLING)
00227   {
00228     icpolarity = (uint8_t)TIM3_ICPOLARITY_FALLING;
00229   }
00230   else
00231   {
00232     icpolarity = (uint8_t)TIM3_ICPOLARITY_RISING;
00233   }
00234   
00235   /* Select the Opposite Input */
00236   if (TIM3_ICSelection == TIM3_ICSELECTION_DIRECTTI)
00237   {
00238     icselection = (uint8_t)TIM3_ICSELECTION_INDIRECTTI;
00239   }
00240   else
00241   {
00242     icselection = (uint8_t)TIM3_ICSELECTION_DIRECTTI;
00243   }
00244   
00245   if (TIM3_Channel != TIM3_CHANNEL_2)
00246   {
00247     /* TI1 Configuration */
00248     TI1_Config((uint8_t)TIM3_ICPolarity, (uint8_t)TIM3_ICSelection,
00249                (uint8_t)TIM3_ICFilter);
00250     
00251     /* Set the Input Capture Prescaler value */
00252     TIM3_SetIC1Prescaler(TIM3_ICPrescaler);
00253     
00254     /* TI2 Configuration */
00255     TI2_Config(icpolarity, icselection, TIM3_ICFilter);
00256     
00257     /* Set the Input Capture Prescaler value */
00258     TIM3_SetIC2Prescaler(TIM3_ICPrescaler);
00259   }
00260   else
00261   {
00262     /* TI2 Configuration */
00263     TI2_Config((uint8_t)TIM3_ICPolarity, (uint8_t)TIM3_ICSelection,
00264                (uint8_t)TIM3_ICFilter);
00265     
00266     /* Set the Input Capture Prescaler value */
00267     TIM3_SetIC2Prescaler(TIM3_ICPrescaler);
00268     
00269     /* TI1 Configuration */
00270     TI1_Config(icpolarity, icselection, TIM3_ICFilter);
00271     
00272     /* Set the Input Capture Prescaler value */
00273     TIM3_SetIC1Prescaler(TIM3_ICPrescaler);
00274   }
00275 }
00276 
00277 /**
00278   * @brief  Enables or disables the TIM3 peripheral.
00279   * @param   NewState new state of the TIM3 peripheral. This parameter can
00280   * be ENABLE or DISABLE.
00281   * @retval None
00282   */
00283 void TIM3_Cmd(FunctionalState NewState)
00284 {
00285   /* Check the parameters */
00286   assert_param(IS_FUNCTIONALSTATE_OK(NewState));
00287   
00288   /* set or Reset the CEN Bit */
00289   if (NewState != DISABLE)
00290   {
00291     TIM3->CR1 |= (uint8_t)TIM3_CR1_CEN;
00292   }
00293   else
00294   {
00295     TIM3->CR1 &= (uint8_t)(~TIM3_CR1_CEN);
00296   }
00297 }
00298 
00299 /**
00300   * @brief  Enables or disables the specified TIM3 interrupts.
00301   * @param   NewState new state of the TIM3 peripheral.
00302   * This parameter can be: ENABLE or DISABLE.
00303   * @param   TIM3_IT specifies the TIM3 interrupts sources to be enabled or disabled.
00304   * This parameter can be any combination of the following values:
00305   *                       - TIM3_IT_UPDATE: TIM3 update Interrupt source
00306   *                       - TIM3_IT_CC1: TIM3 Capture Compare 1 Interrupt source
00307   *                       - TIM3_IT_CC2: TIM3 Capture Compare 2 Interrupt source
00308   *                       - TIM3_IT_CC3: TIM3 Capture Compare 3 Interrupt source
00309   * @param   NewState new state of the TIM3 peripheral.  * @retval None
00310   */
00311 void TIM3_ITConfig(TIM3_IT_TypeDef TIM3_IT, FunctionalState NewState)
00312 {
00313   /* Check the parameters */
00314   assert_param(IS_TIM3_IT_OK(TIM3_IT));
00315   assert_param(IS_FUNCTIONALSTATE_OK(NewState));
00316   
00317   if (NewState != DISABLE)
00318   {
00319     /* Enable the Interrupt sources */
00320     TIM3->IER |= (uint8_t)TIM3_IT;
00321   }
00322   else
00323   {
00324     /* Disable the Interrupt sources */
00325     TIM3->IER &= (uint8_t)(~TIM3_IT);
00326   }
00327 }
00328 
00329 /**
00330   * @brief  Enables or Disables the TIM3 Update event.
00331   * @param   NewState new state of the TIM3 peripheral Preload register. This parameter can
00332   * be ENABLE or DISABLE.
00333   * @retval None
00334   */
00335 void TIM3_UpdateDisableConfig(FunctionalState NewState)
00336 {
00337   /* Check the parameters */
00338   assert_param(IS_FUNCTIONALSTATE_OK(NewState));
00339   
00340   /* Set or Reset the UDIS Bit */
00341   if (NewState != DISABLE)
00342   {
00343     TIM3->CR1 |= TIM3_CR1_UDIS;
00344   }
00345   else
00346   {
00347     TIM3->CR1 &= (uint8_t)(~TIM3_CR1_UDIS);
00348   }
00349 }
00350 
00351 /**
00352   * @brief  Selects the TIM3 Update Request Interrupt source.
00353   * @param   TIM3_UpdateSource specifies the Update source.
00354   * This parameter can be one of the following values
00355   *                       - TIM3_UPDATESOURCE_REGULAR
00356   *                       - TIM3_UPDATESOURCE_GLOBAL
00357   * @retval None
00358   */
00359 void TIM3_UpdateRequestConfig(TIM3_UpdateSource_TypeDef TIM3_UpdateSource)
00360 {
00361   /* Check the parameters */
00362   assert_param(IS_TIM3_UPDATE_SOURCE_OK(TIM3_UpdateSource));
00363   
00364   /* Set or Reset the URS Bit */
00365   if (TIM3_UpdateSource != TIM3_UPDATESOURCE_GLOBAL)
00366   {
00367     TIM3->CR1 |= TIM3_CR1_URS;
00368   }
00369   else
00370   {
00371     TIM3->CR1 &= (uint8_t)(~TIM3_CR1_URS);
00372   }
00373 }
00374 
00375 /**
00376   * @brief  Selects the TIM3�s One Pulse Mode.
00377   * @param   TIM3_OPMode specifies the OPM Mode to be used.
00378   * This parameter can be one of the following values
00379   *                    - TIM3_OPMODE_SINGLE
00380   *                    - TIM3_OPMODE_REPETITIVE
00381   * @retval None
00382   */
00383 void TIM3_SelectOnePulseMode(TIM3_OPMode_TypeDef TIM3_OPMode)
00384 {
00385   /* Check the parameters */
00386   assert_param(IS_TIM3_OPM_MODE_OK(TIM3_OPMode));
00387   
00388   /* Set or Reset the OPM Bit */
00389   if (TIM3_OPMode != TIM3_OPMODE_REPETITIVE)
00390   {
00391     TIM3->CR1 |= TIM3_CR1_OPM;
00392   }
00393   else
00394   {
00395     TIM3->CR1 &= (uint8_t)(~TIM3_CR1_OPM);
00396   }
00397 }
00398 
00399 /**
00400   * @brief  Configures the TIM3 Prescaler.
00401   * @param   Prescaler specifies the Prescaler Register value
00402   * This parameter can be one of the following values
00403   *                       -  TIM3_PRESCALER_1
00404   *                       -  TIM3_PRESCALER_2
00405   *                       -  TIM3_PRESCALER_4
00406   *                       -  TIM3_PRESCALER_8
00407   *                       -  TIM3_PRESCALER_16
00408   *                       -  TIM3_PRESCALER_32
00409   *                       -  TIM3_PRESCALER_64
00410   *                       -  TIM3_PRESCALER_128
00411   *                       -  TIM3_PRESCALER_256
00412   *                       -  TIM3_PRESCALER_512
00413   *                       -  TIM3_PRESCALER_1024
00414   *                       -  TIM3_PRESCALER_2048
00415   *                       -  TIM3_PRESCALER_4096
00416   *                       -  TIM3_PRESCALER_8192
00417   *                       -  TIM3_PRESCALER_16384
00418   *                       -  TIM3_PRESCALER_32768
00419   * @param   TIM3_PSCReloadMode specifies the TIM3 Prescaler Reload mode.
00420   * This parameter can be one of the following values
00421   *                       - TIM3_PSCRELOADMODE_IMMEDIATE: The Prescaler is loaded
00422   *                         immediately.
00423   *                       - TIM3_PSCRELOADMODE_UPDATE: The Prescaler is loaded at
00424   *                         the update event.
00425   * @retval None
00426   */
00427 void TIM3_PrescalerConfig(TIM3_Prescaler_TypeDef Prescaler,
00428                           TIM3_PSCReloadMode_TypeDef TIM3_PSCReloadMode)
00429 {
00430   /* Check the parameters */
00431   assert_param(IS_TIM3_PRESCALER_RELOAD_OK(TIM3_PSCReloadMode));
00432   assert_param(IS_TIM3_PRESCALER_OK(Prescaler));
00433   
00434   /* Set the Prescaler value */
00435   TIM3->PSCR = (uint8_t)Prescaler;
00436   
00437   /* Set or reset the UG Bit */
00438   TIM3->EGR = (uint8_t)TIM3_PSCReloadMode;
00439 }
00440 
00441 /**
00442   * @brief  Forces the TIM3 Channel1 output waveform to active or inactive level.
00443   * @param   TIM3_ForcedAction specifies the forced Action to be set to the output waveform.
00444   * This parameter can be one of the following values:
00445   *                       - TIM3_FORCEDACTION_ACTIVE: Force active level on OC1REF
00446   *                       - TIM3_FORCEDACTION_INACTIVE: Force inactive level on
00447   *                         OC1REF.
00448   * @retval None
00449   */
00450 void TIM3_ForcedOC1Config(TIM3_ForcedAction_TypeDef TIM3_ForcedAction)
00451 {
00452   /* Check the parameters */
00453   assert_param(IS_TIM3_FORCED_ACTION_OK(TIM3_ForcedAction));
00454   
00455   /* Reset the OCM Bits & Configure the Forced output Mode */
00456   TIM3->CCMR1 =  (uint8_t)((uint8_t)(TIM3->CCMR1 & (uint8_t)(~TIM3_CCMR_OCM))  | (uint8_t)TIM3_ForcedAction);
00457 }
00458 
00459 /**
00460   * @brief  Forces the TIM3 Channel2 output waveform to active or inactive level.
00461   * @param   TIM3_ForcedAction specifies the forced Action to be set to the output waveform.
00462   * This parameter can be one of the following values:
00463   *                       - TIM3_FORCEDACTION_ACTIVE: Force active level on OC2REF
00464   *                       - TIM3_FORCEDACTION_INACTIVE: Force inactive level on
00465   *                         OC2REF.
00466   * @retval None
00467   */
00468 void TIM3_ForcedOC2Config(TIM3_ForcedAction_TypeDef TIM3_ForcedAction)
00469 {
00470   /* Check the parameters */
00471   assert_param(IS_TIM3_FORCED_ACTION_OK(TIM3_ForcedAction));
00472   
00473   /* Reset the OCM Bits & Configure the Forced output Mode */
00474   TIM3->CCMR2 =  (uint8_t)((uint8_t)(TIM3->CCMR2 & (uint8_t)(~TIM3_CCMR_OCM)) | (uint8_t)TIM3_ForcedAction);
00475 }
00476 
00477 /**
00478   * @brief  Enables or disables TIM3 peripheral Preload register on ARR.
00479   * @param   NewState new state of the TIM3 peripheral Preload register.
00480   * This parameter can be ENABLE or DISABLE.
00481   * @retval None
00482   */
00483 void TIM3_ARRPreloadConfig(FunctionalState NewState)
00484 {
00485   /* Check the parameters */
00486   assert_param(IS_FUNCTIONALSTATE_OK(NewState));
00487   
00488   /* Set or Reset the ARPE Bit */
00489   if (NewState != DISABLE)
00490   {
00491     TIM3->CR1 |= TIM3_CR1_ARPE;
00492   }
00493   else
00494   {
00495     TIM3->CR1 &= (uint8_t)(~TIM3_CR1_ARPE);
00496   }
00497 }
00498 
00499 /**
00500   * @brief  Enables or disables the TIM3 peripheral Preload Register on CCR1.
00501   * @param   NewState new state of the Capture Compare Preload register.
00502   * This parameter can be ENABLE or DISABLE.
00503   * @retval None
00504   */
00505 void TIM3_OC1PreloadConfig(FunctionalState NewState)
00506 {
00507   /* Check the parameters */
00508   assert_param(IS_FUNCTIONALSTATE_OK(NewState));
00509   
00510   /* Set or Reset the OC1PE Bit */
00511   if (NewState != DISABLE)
00512   {
00513     TIM3->CCMR1 |= TIM3_CCMR_OCxPE;
00514   }
00515   else
00516   {
00517     TIM3->CCMR1 &= (uint8_t)(~TIM3_CCMR_OCxPE);
00518   }
00519 }
00520 
00521 /**
00522   * @brief  Enables or disables the TIM3 peripheral Preload Register on CCR2.
00523   * @param   NewState new state of the Capture Compare Preload register.
00524   * This parameter can be ENABLE or DISABLE.
00525   * @retval None
00526   */
00527 void TIM3_OC2PreloadConfig(FunctionalState NewState)
00528 {
00529   /* Check the parameters */
00530   assert_param(IS_FUNCTIONALSTATE_OK(NewState));
00531   
00532   /* Set or Reset the OC2PE Bit */
00533   if (NewState != DISABLE)
00534   {
00535     TIM3->CCMR2 |= TIM3_CCMR_OCxPE;
00536   }
00537   else
00538   {
00539     TIM3->CCMR2 &= (uint8_t)(~TIM3_CCMR_OCxPE);
00540   }
00541 }
00542 
00543 /**
00544   * @brief  Configures the TIM3 event to be generated by software.
00545   * @param   TIM3_EventSource specifies the event source.
00546   * This parameter can be one of the following values:
00547   *                       - TIM3_EVENTSOURCE_UPDATE: TIM3 update Event source
00548   *                       - TIM3_EVENTSOURCE_CC1: TIM3 Capture Compare 1 Event source
00549   *                       - TIM3_EVENTSOURCE_CC2: TIM3 Capture Compare 2 Event source
00550   * @retval None
00551   */
00552 void TIM3_GenerateEvent(TIM3_EventSource_TypeDef TIM3_EventSource)
00553 {
00554   /* Check the parameters */
00555   assert_param(IS_TIM3_EVENT_SOURCE_OK(TIM3_EventSource));
00556   
00557   /* Set the event sources */
00558   TIM3->EGR = (uint8_t)TIM3_EventSource;
00559 }
00560 
00561 /**
00562   * @brief  Configures the TIM3 Channel 1 polarity.
00563   * @param   TIM3_OCPolarity specifies the OC1 Polarity.
00564   * This parameter can be one of the following values:
00565   *                       - TIM3_OCPOLARITY_LOW: Output Compare active low
00566   *                       - TIM3_OCPOLARITY_HIGH: Output Compare active high
00567   * @retval None
00568   */
00569 void TIM3_OC1PolarityConfig(TIM3_OCPolarity_TypeDef TIM3_OCPolarity)
00570 {
00571   /* Check the parameters */
00572   assert_param(IS_TIM3_OC_POLARITY_OK(TIM3_OCPolarity));
00573   
00574   /* Set or Reset the CC1P Bit */
00575   if (TIM3_OCPolarity != TIM3_OCPOLARITY_HIGH)
00576   {
00577     TIM3->CCER1 |= TIM3_CCER1_CC1P;
00578   }
00579   else
00580   {
00581     TIM3->CCER1 &= (uint8_t)(~TIM3_CCER1_CC1P);
00582   }
00583 }
00584 
00585 /**
00586   * @brief  Configures the TIM3 Channel 2 polarity.
00587   * @param   TIM3_OCPolarity specifies the OC2 Polarity.
00588   * This parameter can be one of the following values:
00589   *                       - TIM3_OCPOLARITY_LOW: Output Compare active low
00590   *                       - TIM3_OCPOLARITY_HIGH: Output Compare active high
00591   * @retval None
00592   */
00593 void TIM3_OC2PolarityConfig(TIM3_OCPolarity_TypeDef TIM3_OCPolarity)
00594 {
00595   /* Check the parameters */
00596   assert_param(IS_TIM3_OC_POLARITY_OK(TIM3_OCPolarity));
00597   
00598   /* Set or Reset the CC2P Bit */
00599   if (TIM3_OCPolarity != TIM3_OCPOLARITY_HIGH)
00600   {
00601     TIM3->CCER1 |= TIM3_CCER1_CC2P;
00602   }
00603   else
00604   {
00605     TIM3->CCER1 &= (uint8_t)(~TIM3_CCER1_CC2P);
00606   }
00607 }
00608 
00609 /**
00610   * @brief  Enables or disables the TIM3 Capture Compare Channel x.
00611   * @param   TIM3_Channel specifies the TIM3 Channel.
00612   * This parameter can be one of the following values:
00613   *                       - TIM3_CHANNEL_1: TIM3 Channel1
00614   *                       - TIM3_CHANNEL_2: TIM3 Channel2
00615   * @param   NewState specifies the TIM3 Channel CCxE bit new state.
00616   * This parameter can be: ENABLE or DISABLE.
00617   * @retval None
00618   */
00619 void TIM3_CCxCmd(TIM3_Channel_TypeDef TIM3_Channel, FunctionalState NewState)
00620 {
00621   /* Check the parameters */
00622   assert_param(IS_TIM3_CHANNEL_OK(TIM3_Channel));
00623   assert_param(IS_FUNCTIONALSTATE_OK(NewState));
00624   
00625   if (TIM3_Channel == TIM3_CHANNEL_1)
00626   {
00627     /* Set or Reset the CC1E Bit */
00628     if (NewState != DISABLE)
00629     {
00630       TIM3->CCER1 |= TIM3_CCER1_CC1E;
00631     }
00632     else
00633     {
00634       TIM3->CCER1 &= (uint8_t)(~TIM3_CCER1_CC1E);
00635     }
00636     
00637   }
00638   else
00639   {
00640     /* Set or Reset the CC2E Bit */
00641     if (NewState != DISABLE)
00642     {
00643       TIM3->CCER1 |= TIM3_CCER1_CC2E;
00644     }
00645     else
00646     {
00647       TIM3->CCER1 &= (uint8_t)(~TIM3_CCER1_CC2E);
00648     }
00649   }
00650 }
00651 
00652 /**
00653   * @brief  Selects the TIM3 Output Compare Mode. This function disables the
00654   * selected channel before changing the Output Compare Mode. User has to
00655   * enable this channel using TIM3_CCxCmd and TIM3_CCxNCmd functions.
00656   * @param   TIM3_Channel specifies the TIM3 Channel.
00657   * This parameter can be one of the following values:
00658   *                       - TIM3_CHANNEL_1: TIM3 Channel1
00659   *                       - TIM3_CHANNEL_2: TIM3 Channel2
00660   * @param   TIM3_OCMode specifies the TIM3 Output Compare Mode.
00661   * This parameter can be one of the following values:
00662   *                       - TIM3_OCMODE_TIMING
00663   *                       - TIM3_OCMODE_ACTIVE
00664   *                       - TIM3_OCMODE_TOGGLE
00665   *                       - TIM3_OCMODE_PWM1
00666   *                       - TIM3_OCMODE_PWM2
00667   *                       - TIM3_FORCEDACTION_ACTIVE
00668   *                       - TIM3_FORCEDACTION_INACTIVE
00669   * @retval None
00670   */
00671 void TIM3_SelectOCxM(TIM3_Channel_TypeDef TIM3_Channel, TIM3_OCMode_TypeDef TIM3_OCMode)
00672 {
00673   /* Check the parameters */
00674   assert_param(IS_TIM3_CHANNEL_OK(TIM3_Channel));
00675   assert_param(IS_TIM3_OCM_OK(TIM3_OCMode));
00676   
00677   if (TIM3_Channel == TIM3_CHANNEL_1)
00678   {
00679     /* Disable the Channel 1: Reset the CCE Bit */
00680     TIM3->CCER1 &= (uint8_t)(~TIM3_CCER1_CC1E);
00681     
00682     /* Reset the Output Compare Bits & Set the Output Compare Mode */
00683     TIM3->CCMR1 = (uint8_t)((uint8_t)(TIM3->CCMR1 & (uint8_t)(~TIM3_CCMR_OCM)) | (uint8_t)TIM3_OCMode);
00684   }
00685   else
00686   {
00687     /* Disable the Channel 2: Reset the CCE Bit */
00688     TIM3->CCER1 &= (uint8_t)(~TIM3_CCER1_CC2E);
00689     
00690     /* Reset the Output Compare Bits & Set the Output Compare Mode */
00691     TIM3->CCMR2 = (uint8_t)((uint8_t)(TIM3->CCMR2 & (uint8_t)(~TIM3_CCMR_OCM)) | (uint8_t)TIM3_OCMode);
00692   }
00693 }
00694 
00695 /**
00696   * @brief  Sets the TIM3 Counter Register value.
00697   * @param   Counter specifies the Counter register new value.
00698   * This parameter is between 0x0000 and 0xFFFF.
00699   * @retval None
00700   */
00701 void TIM3_SetCounter(uint16_t Counter)
00702 {
00703   /* Set the Counter Register value */
00704   TIM3->CNTRH = (uint8_t)(Counter >> 8);
00705   TIM3->CNTRL = (uint8_t)(Counter);
00706 }
00707 
00708 /**
00709   * @brief  Sets the TIM3 Autoreload Register value.
00710   * @param   Autoreload specifies the Autoreload register new value.
00711   * This parameter is between 0x0000 and 0xFFFF.
00712   * @retval None
00713   */
00714 void TIM3_SetAutoreload(uint16_t Autoreload)
00715 {
00716   /* Set the Autoreload Register value */
00717   TIM3->ARRH = (uint8_t)(Autoreload >> 8);
00718   TIM3->ARRL = (uint8_t)(Autoreload);
00719 }
00720 
00721 /**
00722   * @brief  Sets the TIM3 Capture Compare1 Register value.
00723   * @param   Compare1 specifies the Capture Compare1 register new value.
00724   * This parameter is between 0x0000 and 0xFFFF.
00725   * @retval None
00726   */
00727 void TIM3_SetCompare1(uint16_t Compare1)
00728 {
00729   /* Set the Capture Compare1 Register value */
00730   TIM3->CCR1H = (uint8_t)(Compare1 >> 8);
00731   TIM3->CCR1L = (uint8_t)(Compare1);
00732 }
00733 
00734 /**
00735   * @brief  Sets the TIM3 Capture Compare2 Register value.
00736   * @param   Compare2 specifies the Capture Compare2 register new value.
00737   * This parameter is between 0x0000 and 0xFFFF.
00738   * @retval None
00739   */
00740 void TIM3_SetCompare2(uint16_t Compare2)
00741 {
00742   /* Set the Capture Compare2 Register value */
00743   TIM3->CCR2H = (uint8_t)(Compare2 >> 8);
00744   TIM3->CCR2L = (uint8_t)(Compare2);
00745 }
00746 
00747 /**
00748   * @brief  Sets the TIM3 Input Capture 1 prescaler.
00749   * @param   TIM3_IC1Prescaler specifies the Input Capture prescaler new value
00750   * This parameter can be one of the following values:
00751   *                       - TIM3_ICPSC_DIV1: no prescaler
00752   *                       - TIM3_ICPSC_DIV2: capture is done once every 2 events
00753   *                       - TIM3_ICPSC_DIV4: capture is done once every 4 events
00754   *                       - TIM3_ICPSC_DIV8: capture is done once every 8 events
00755   * @retval None
00756   */
00757 void TIM3_SetIC1Prescaler(TIM3_ICPSC_TypeDef TIM3_IC1Prescaler)
00758 {
00759   /* Check the parameters */
00760   assert_param(IS_TIM3_IC_PRESCALER_OK(TIM3_IC1Prescaler));
00761   
00762   /* Reset the IC1PSC Bits & Set the IC1PSC value */
00763   TIM3->CCMR1 = (uint8_t)((uint8_t)(TIM3->CCMR1 & (uint8_t)(~TIM3_CCMR_ICxPSC)) | (uint8_t)TIM3_IC1Prescaler);
00764 }
00765 
00766 /**
00767   * @brief  Sets the TIM3 Input Capture 2 prescaler.
00768   * @param   TIM3_IC2Prescaler specifies the Input Capture prescaler new value
00769   * This parameter can be one of the following values:
00770   *                       - TIM3_ICPSC_DIV1: no prescaler
00771   *                       - TIM3_ICPSC_DIV2: capture is done once every 2 events
00772   *                       - TIM3_ICPSC_DIV4: capture is done once every 4 events
00773   *                       - TIM3_ICPSC_DIV8: capture is done once every 8 events
00774   * @retval None
00775   */
00776 void TIM3_SetIC2Prescaler(TIM3_ICPSC_TypeDef TIM3_IC2Prescaler)
00777 {
00778   /* Check the parameters */
00779   assert_param(IS_TIM3_IC_PRESCALER_OK(TIM3_IC2Prescaler));
00780   
00781   /* Reset the IC1PSC Bits & Set the IC1PSC value */
00782   TIM3->CCMR2 = (uint8_t)((uint8_t)(TIM3->CCMR2 & (uint8_t)(~TIM3_CCMR_ICxPSC)) | (uint8_t)TIM3_IC2Prescaler);
00783 }
00784 
00785 /**
00786   * @brief  Gets the TIM3 Input Capture 1 value.
00787   * @param  None
00788   * @retval Capture Compare 1 Register value.
00789   */
00790 uint16_t TIM3_GetCapture1(void)
00791 {
00792   /* Get the Capture 1 Register value */
00793   uint16_t tmpccr1 = 0;
00794   uint8_t tmpccr1l=0, tmpccr1h=0;
00795   
00796   tmpccr1h = TIM3->CCR1H;
00797   tmpccr1l = TIM3->CCR1L;
00798   
00799   tmpccr1 = (uint16_t)(tmpccr1l);
00800   tmpccr1 |= (uint16_t)((uint16_t)tmpccr1h << 8);
00801   /* Get the Capture 1 Register value */
00802   return (uint16_t)tmpccr1;
00803 }
00804 
00805 /**
00806   * @brief  Gets the TIM3 Input Capture 2 value.
00807   * @param  None
00808   * @retval Capture Compare 2 Register value.
00809   */
00810 uint16_t TIM3_GetCapture2(void)
00811 {
00812   /* Get the Capture 2 Register value */
00813   uint16_t tmpccr2 = 0;
00814   uint8_t tmpccr2l=0, tmpccr2h=0;
00815   
00816   tmpccr2h = TIM3->CCR2H;
00817   tmpccr2l = TIM3->CCR2L;
00818   
00819   tmpccr2 = (uint16_t)(tmpccr2l);
00820   tmpccr2 |= (uint16_t)((uint16_t)tmpccr2h << 8);
00821   /* Get the Capture 2 Register value */
00822   return (uint16_t)tmpccr2;
00823 }
00824 
00825 /**
00826   * @brief  Gets the TIM3 Counter value.
00827   * @param  None
00828   * @retval Counter Register value.
00829   */
00830 uint16_t TIM3_GetCounter(void)
00831 {
00832   uint16_t tmpcntr = 0;
00833   
00834   tmpcntr = ((uint16_t)TIM3->CNTRH << 8);
00835   /* Get the Counter Register value */
00836   return (uint16_t)( tmpcntr| (uint16_t)(TIM3->CNTRL));
00837 }
00838 
00839 /**
00840   * @brief  Gets the TIM3 Prescaler value.
00841   * @param  None
00842   * @retval Prescaler Register configuration value @ref TIM3_Prescaler_TypeDef.
00843   */
00844 TIM3_Prescaler_TypeDef TIM3_GetPrescaler(void)
00845 {
00846   /* Get the Prescaler Register value */
00847   return (TIM3_Prescaler_TypeDef)(TIM3->PSCR);
00848 }
00849 
00850 /**
00851   * @brief  Checks whether the specified TIM3 flag is set or not.
00852   * @param   TIM3_FLAG specifies the flag to check.
00853   * This parameter can be one of the following values:
00854   *                       - TIM3_FLAG_UPDATE: TIM3 update Flag
00855   *                       - TIM3_FLAG_CC1: TIM3 Capture Compare 1 Flag
00856   *                       - TIM3_FLAG_CC2: TIM3 Capture Compare 2 Flag
00857   *                       - TIM3_FLAG_CC1OF: TIM3 Capture Compare 1 over capture Flag
00858   *                       - TIM3_FLAG_CC2OF: TIM3 Capture Compare 2 over capture Flag
00859   * @retval FlagStatus The new state of TIM3_FLAG (SET or RESET).
00860   */
00861 FlagStatus TIM3_GetFlagStatus(TIM3_FLAG_TypeDef TIM3_FLAG)
00862 {
00863   FlagStatus bitstatus = RESET;
00864   uint8_t tim3_flag_l = 0, tim3_flag_h = 0;
00865   
00866   /* Check the parameters */
00867   assert_param(IS_TIM3_GET_FLAG_OK(TIM3_FLAG));
00868   
00869   tim3_flag_l = (uint8_t)(TIM3->SR1 & (uint8_t)TIM3_FLAG);
00870   tim3_flag_h = (uint8_t)((uint16_t)TIM3_FLAG >> 8);
00871   
00872   if (((tim3_flag_l) | (uint8_t)(TIM3->SR2 & tim3_flag_h)) != (uint8_t)RESET )
00873   {
00874     bitstatus = SET;
00875   }
00876   else
00877   {
00878     bitstatus = RESET;
00879   }
00880   return (FlagStatus)bitstatus;
00881 }
00882 
00883 /**
00884   * @brief  Clears the TIM3�s pending flags.
00885   * @param   TIM3_FLAG specifies the flag to clear.
00886   * This parameter can be one of the following values:
00887   *                       - TIM3_FLAG_UPDATE: TIM3 update Flag
00888   *                       - TIM3_FLAG_CC1: TIM3 Capture Compare 1 Flag
00889   *                       - TIM3_FLAG_CC2: TIM3 Capture Compare 2 Flag
00890   *                       - TIM3_FLAG_CC1OF: TIM3 Capture Compare 1 over capture Flag
00891   *                       - TIM3_FLAG_CC2OF: TIM3 Capture Compare 2 over capture Flag
00892   * @retval None.
00893   */
00894 void TIM3_ClearFlag(TIM3_FLAG_TypeDef TIM3_FLAG)
00895 {
00896   /* Check the parameters */
00897   assert_param(IS_TIM3_CLEAR_FLAG_OK(TIM3_FLAG));
00898   
00899   /* Clear the flags (rc_w0) clear this bit by writing 0. Writing �1� has no effect*/
00900   TIM3->SR1 = (uint8_t)(~((uint8_t)(TIM3_FLAG)));
00901   TIM3->SR2 = (uint8_t)(~((uint8_t)((uint16_t)TIM3_FLAG >> 8)));
00902 }
00903 
00904 /**
00905   * @brief  Checks whether the TIM3 interrupt has occurred or not.
00906   * @param   TIM3_IT specifies the TIM3 interrupt source to check.
00907   * This parameter can be one of the following values:
00908   *                       - TIM3_IT_UPDATE: TIM3 update Interrupt source
00909   *                       - TIM3_IT_CC1: TIM3 Capture Compare 1 Interrupt source
00910   *                       - TIM3_IT_CC2: TIM3 Capture Compare 2 Interrupt source
00911   * @retval ITStatus The new state of the TIM3_IT(SET or RESET).
00912   */
00913 ITStatus TIM3_GetITStatus(TIM3_IT_TypeDef TIM3_IT)
00914 {
00915   ITStatus bitstatus = RESET;
00916   uint8_t TIM3_itStatus = 0, TIM3_itEnable = 0;
00917   
00918   /* Check the parameters */
00919   assert_param(IS_TIM3_GET_IT_OK(TIM3_IT));
00920   
00921   TIM3_itStatus = (uint8_t)(TIM3->SR1 & TIM3_IT);
00922   
00923   TIM3_itEnable = (uint8_t)(TIM3->IER & TIM3_IT);
00924   
00925   if ((TIM3_itStatus != (uint8_t)RESET ) && (TIM3_itEnable != (uint8_t)RESET ))
00926   {
00927     bitstatus = SET;
00928   }
00929   else
00930   {
00931     bitstatus = RESET;
00932   }
00933   return (ITStatus)(bitstatus);
00934 }
00935 
00936 /**
00937   * @brief  Clears the TIM3's interrupt pending bits.
00938   * @param   TIM3_IT specifies the pending bit to clear.
00939   * This parameter can be one of the following values:
00940   *                       - TIM3_IT_UPDATE: TIM3 update Interrupt source
00941   *                       - TIM3_IT_CC1: TIM3 Capture Compare 1 Interrupt source
00942   *                       - TIM3_IT_CC2: TIM3 Capture Compare 2 Interrupt source
00943   * @retval None.
00944   */
00945 void TIM3_ClearITPendingBit(TIM3_IT_TypeDef TIM3_IT)
00946 {
00947   /* Check the parameters */
00948   assert_param(IS_TIM3_IT_OK(TIM3_IT));
00949   
00950   /* Clear the IT pending Bit */
00951   TIM3->SR1 = (uint8_t)(~TIM3_IT);
00952 }
00953 
00954 /**
00955   * @brief  Configure the TI1 as Input.
00956   * @param   TIM3_ICPolarity  The Input Polarity.
00957   * This parameter can be one of the following values:
00958   *                       - TIM3_ICPOLARITY_FALLING
00959   *                       - TIM3_ICPOLARITY_RISING
00960   * @param   TIM3_ICSelection specifies the input to be used.
00961   * This parameter can be one of the following values:
00962   *                       - TIM3_ICSELECTION_DIRECTTI: TIM3 Input 1 is selected to
00963   *                         be connected to IC1.
00964   *                       - TIM3_ICSELECTION_INDIRECTTI: TIM3 Input 1 is selected to
00965   *                         be connected to IC2.
00966   * @param   TIM3_ICFilter Specifies the Input Capture Filter.
00967   * This parameter must be a value between 0x00 and 0x0F.
00968   * @retval None
00969   */
00970 static void TI1_Config(uint8_t TIM3_ICPolarity,
00971                        uint8_t TIM3_ICSelection,
00972                        uint8_t TIM3_ICFilter)
00973 {
00974   /* Disable the Channel 1: Reset the CCE Bit */
00975   TIM3->CCER1 &= (uint8_t)(~TIM3_CCER1_CC1E);
00976   
00977   /* Select the Input and set the filter */
00978   TIM3->CCMR1 = (uint8_t)((uint8_t)(TIM3->CCMR1 & (uint8_t)(~( TIM3_CCMR_CCxS | TIM3_CCMR_ICxF))) | (uint8_t)(( (TIM3_ICSelection)) | ((uint8_t)( TIM3_ICFilter << 4))));
00979   
00980   /* Select the Polarity */
00981   if (TIM3_ICPolarity != TIM3_ICPOLARITY_RISING)
00982   {
00983     TIM3->CCER1 |= TIM3_CCER1_CC1P;
00984   }
00985   else
00986   {
00987     TIM3->CCER1 &= (uint8_t)(~TIM3_CCER1_CC1P);
00988   }
00989   /* Set the CCE Bit */
00990   TIM3->CCER1 |= TIM3_CCER1_CC1E;
00991 }
00992 
00993 /**
00994   * @brief  Configure the TI2 as Input.
00995   * @param   TIM3_ICPolarity  The Input Polarity.
00996   * This parameter can be one of the following values:
00997   *                       - TIM3_ICPOLARITY_FALLING
00998   *                       - TIM3_ICPOLARITY_RISING
00999   * @param   TIM3_ICSelection specifies the input to be used.
01000   * This parameter can be one of the following values:
01001   *                       - TIM3_ICSELECTION_DIRECTTI: TIM3 Input 2 is selected to
01002   *                         be connected to IC2.
01003   *                       - TIM3_ICSELECTION_INDIRECTTI: TIM3 Input 2 is selected to
01004   *                         be connected to IC1.
01005   * @param   TIM3_ICFilter Specifies the Input Capture Filter.
01006   * This parameter must be a value between 0x00 and 0x0F.
01007   * @retval None
01008   */
01009 static void TI2_Config(uint8_t TIM3_ICPolarity,
01010                        uint8_t TIM3_ICSelection,
01011                        uint8_t TIM3_ICFilter)
01012 {
01013   /* Disable the Channel 2: Reset the CCE Bit */
01014   TIM3->CCER1 &=  (uint8_t)(~TIM3_CCER1_CC2E);
01015   
01016   /* Select the Input and set the filter */
01017   TIM3->CCMR2 = (uint8_t)((uint8_t)(TIM3->CCMR2 & (uint8_t)(~( TIM3_CCMR_CCxS |
01018                                                               TIM3_CCMR_ICxF    ))) | (uint8_t)(( (TIM3_ICSelection)) | 
01019                                                                                                 ((uint8_t)( TIM3_ICFilter << 4))));
01020   
01021   /* Select the Polarity */
01022   if (TIM3_ICPolarity != TIM3_ICPOLARITY_RISING)
01023   {
01024     TIM3->CCER1 |= TIM3_CCER1_CC2P;
01025   }
01026   else
01027   {
01028     TIM3->CCER1 &= (uint8_t)(~TIM3_CCER1_CC2P);
01029   }
01030   
01031   /* Set the CCE Bit */
01032   TIM3->CCER1 |= TIM3_CCER1_CC2E;
01033 }
01034 
01035 /**
01036   * @}
01037   */
01038   
01039   /**
01040   * @}
01041   */
01042   
01043 
01044 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
STM8 Standard Peripherals Library: Footer

 

 

 

      For complete documentation on STM8 8-bit Microcontrollers platform visit www.st.com