STM8S/A Standard Peripherals Firmware Library: main.c Source File

STM8S/A

STM8S_StdPeriph_Examples/TIM5/TIM5_Synchronisation_With_TIM6/main.c
Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    TIM5_Synchronisation_with_TIM6\main.c
00004   * @author  MCD Application Team
00005   * @version  V2.2.0
00006   * @date     30-September-2014
00007   * @brief   This file contains the main function for TIM5 example.
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.h"
00030 
00031 /**
00032   * @addtogroup TIM5_Synchronisation_with_TIM6
00033   * @{
00034   */
00035 
00036 /* Private typedef -----------------------------------------------------------*/
00037 /* Private define ------------------------------------------------------------*/
00038 #define TIMEOUT ((uint8_t)0xFF)
00039 /* Private macro -------------------------------------------------------------*/
00040 /* Private variables ---------------------------------------------------------*/
00041 /* Private function prototypes -----------------------------------------------*/
00042 static void TIM5_Config(void);
00043 static void TIM6_Config(void);
00044 static FunctionalState TIM5_Status(void);
00045 /* Private functions ---------------------------------------------------------*/
00046 static FunctionalState TIM5_Status(void) 
00047 {
00048    return ((FunctionalState)(TIM5->CR1 & TIM5_CR1_CEN));
00049 }
00050 /* Public functions ----------------------------------------------------------*/
00051 /**
00052   * @brief  Main program.
00053   * @param  None
00054   * @retval None
00055   */
00056 void main(void)
00057 {
00058   
00059   __IO uint8_t Result = 0;
00060   __IO uint8_t timeout = TIMEOUT;
00061   
00062   /* TIM5 configuration -----------------------------------------*/
00063   TIM5_Config();   
00064 
00065   /* TIM6 configuration -----------------------------------------*/
00066   TIM6_Config();   
00067 
00068   /*Enable TIM6*/
00069   TIM6_Cmd(ENABLE);/* if this line is commented, TIM6 will not be enabled and */
00070                    /* TIM5  will not detect an Edge on its TRGI => Result =0  */
00071   
00072   while((TIM5_Status() == DISABLE) && (timeout != 0))
00073   {
00074     /* Decrement timeout */
00075     timeout--;
00076   }
00077   
00078   if (TIM5_Status() != DISABLE)
00079   {
00080     /*If the program counter reaches this section, 
00081     the TIM5 is correctly triggered by TIM6 */
00082     /*Insert break point in the following line */
00083     Result = 1;
00084   }
00085   else
00086   {
00087     /*If the program counter reaches this section, 
00088       the TIM5 is not correctly triggered by TIM6 */
00089     /*Insert break point in the following line */
00090     Result = 0;
00091   }
00092   /* infinite loop */
00093   while(1)
00094   {
00095   }
00096 }
00097 
00098 /**
00099   * @brief  TIM5 Configuration.
00100   * @param  None
00101   * @retval None
00102   */
00103 static void TIM5_Config(void)
00104 {
00105   /*DeInit TIM5 registers*/
00106   TIM5_DeInit();
00107   
00108   /* Time base configuration */
00109   TIM5_TimeBaseInit(TIM5_PRESCALER_1, 0xFF );
00110   
00111   /* Select TIM6 as source of TIM5 Trigger Input*/
00112   TIM5_SelectInputTrigger(TIM5_TS_TIM6);
00113   
00114   /* configurate TIM5 as slave of Trigger input*/
00115   TIM5_SelectSlaveMode(TIM5_SLAVEMODE_TRIGGER);
00116 }
00117 
00118 /**
00119   * @brief  TIM6 Configuration.
00120   * @param  None
00121   * @retval None
00122   */
00123 static void TIM6_Config(void)
00124 {
00125   /*DeInit TIM6 registers*/
00126   TIM6_DeInit();
00127   
00128   /* Time base configuration */  
00129   TIM6_TimeBaseInit(TIM6_PRESCALER_1, 0xFF );  
00130   
00131   /* Select TIM6 Update event as source of TIM6 Trigger Output*/
00132   TIM6_SelectOutputTrigger(TIM6_TRGOSOURCE_UPDATE);  
00133 }
00134 
00135 #ifdef USE_FULL_ASSERT
00136 
00137 /**
00138   * @brief  Reports the name of the source file and the source line number
00139   *   where the assert_param error has occurred.
00140   * @param file: pointer to the source file name
00141   * @param line: assert_param error line source number
00142   * @retval None
00143   */
00144 void assert_failed(uint8_t* file, uint32_t line)
00145 { 
00146   /* User can add his own implementation to report the file name and line number,
00147      ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
00148 
00149   /* Infinite loop */
00150   while (1)
00151   {
00152   }
00153 }
00154 #endif
00155 
00156 /**
00157   * @}
00158   */
00159 
00160 
00161 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
STM8 Standard Peripherals Library: Footer

 

 

 

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