1 /**
2   ******************************************************************************
3   * @file    tae32f53xx_ll_tmr.c
4   * @author  MCD Application Team
5   * @brief   TMR LL module driver.
6   *          This file provides firmware functions to manage the following
7   *          functionalities of the Timer (TMR) peripheral:
8   *           + TMR Time Initialization and De-Initialization function
9   *           + TMR Input Capture and Output Compare configure functions
10   *           + TMR Start and Stop functions
11   *           + TMR event software generate function
12   *           + TMR internal trigger signal configure function
13   *           + TMR interrupt handler and callback functions
14   *
15   ******************************************************************************
16   * @attention
17   *
18   * <h2><center>&copy; Copyright (c) 2020 Tai-Action.
19   * All rights reserved.</center></h2>
20   *
21   * This software is licensed by Tai-Action under BSD 3-Clause license,
22   * the "License"; You may not use this file except in compliance with the
23   * License. You may obtain a copy of the License at:
24   *                        opensource.org/licenses/BSD-3-Clause
25   *
26   ******************************************************************************
27   */
28 
29 /* Includes ------------------------------------------------------------------*/
30 #include "tae32f53xx_ll.h"
31 
32 
33 #define DBG_TAG             "TMR LL"
34 #define DBG_LVL             DBG_ERROR
35 #include "dbg/tae32f53xx_dbg.h"
36 
37 
38 /** @addtogroup TAE32F53xx_LL_Driver
39   * @{
40   */
41 
42 /** @defgroup TMR_LL TMR LL
43   * @brief    TMR LL module driver.
44   * @{
45   */
46 
47 #ifdef LL_TMR_MODULE_ENABLED
48 
49 /* Private typedef -----------------------------------------------------------*/
50 /* Private define ------------------------------------------------------------*/
51 /* Private macro -------------------------------------------------------------*/
52 /* Private variables ---------------------------------------------------------*/
53 /* Private function prototypes -----------------------------------------------*/
54 /** @defgroup TMR_LL_Private_Functions TMR LL Private Functions
55   * @brief    TMR LL Private Functions
56   * @{
57   */
58 static void TMR_TB_SetConfig(TMR_TypeDef *Instance, TMR_TB_InitTypeDef *Config);
59 static void TMR_IC_SetConfig(TMR_TypeDef *Instance, TMR_IC_InitTypeDef *Config);
60 static void TMR_OC_SetConfig(TMR_TypeDef *Instance, TMR_OC_InitTypeDef *Config);
61 static void TMR_EXT_SetConfig(TMR_TypeDef *Instance, TMR_EXT_InitTypeDef *Config);
62 /**
63   * @}
64   */
65 
66 
67 /* Exported functions --------------------------------------------------------*/
68 /** @defgroup TMR_LL_Exported_Functions TMR LL Exported Functions
69   * @brief    TMR LL Exported Functions
70   * @{
71   */
72 
73 /** @defgroup TMR_LL_Exported_Functions_Group1 Initialization and De-Initialization functions
74   * @brief    Initialization and De-Initialization functions
75 @verbatim
76   ==============================================================================
77               ##### Initialization and De-Initialization functions #####
78   ==============================================================================
79   [..]
80     This section provides functions allowing to:
81     (+) Initialize and configure the TMR base unit.
82     (+) De-initialize the TMR base unit.
83 
84 @endverbatim
85   * @{
86   */
87 
88 /**
89   * @brief  Initialize the TMR peripheral
90   * @param  Instance TMR peripheral instance
91   * @param  Init pointer to a TMR_InitTypeDef structure that contains the configuration
92   *         information for the specified TMR peripheral.
93   * @note   InputCapture and OutputCompare feature must NOT be enabled at the same time
94   *         in one single TMR peripheral.
95   * @return status of the initialization
96   */
LL_TMR_Init(TMR_TypeDef * Instance,TMR_InitTypeDef * Init)97 LL_StatusETypeDef LL_TMR_Init(TMR_TypeDef *Instance, TMR_InitTypeDef *Init)
98 {
99     /* Check the parameters */
100     assert_param(IS_TMR_ALL_INSTANCE(Instance));
101     assert_param(Init != NULL);
102     /* Input Capture and Output Compare can not be enabled in one TMR at the same time */
103     assert_param(!((Init->ICInit.ICEnable == ENABLE) && (Init->OCInit.OCEnable == ENABLE)));
104 
105     /* Handle Something */
106     LL_TMR_MspInit(Instance);
107 
108     /* Disable Capture/Compare before initialization */
109     __LL_TMR_CC_DISABLE(Instance);
110 
111     /* Stop Counter before initialization */
112     __LL_TMR_DISABLE(Instance);
113 
114     /* Set configuration to TimeBase unit */
115     TMR_TB_SetConfig(Instance, &Init->TBInit);
116 
117     /* Set configuration for Input Capture feature */
118     TMR_IC_SetConfig(Instance, &Init->ICInit);
119 
120     /* Set configuration for Output Compare feature */
121     TMR_OC_SetConfig(Instance, &Init->OCInit);
122 
123     /* Set configuration for Export Trigger Event feature */
124     TMR_EXT_SetConfig(Instance, &Init->ExtInit);
125 
126     /* Return function status */
127     return LL_OK;
128 }
129 
130 /**
131   * @brief  DeInitializes the timer
132   * @param  Instance TMR peripheral instance
133   * @return status of the initialization
134   */
LL_TMR_DeInit(TMR_TypeDef * Instance)135 LL_StatusETypeDef LL_TMR_DeInit(TMR_TypeDef *Instance)
136 {
137     /* Check the TMR initiation struct allocation */
138     assert_param(IS_TMR_ALL_INSTANCE(Instance));
139 
140     /* Stop Counter */
141     __LL_TMR_DISABLE(Instance);
142 
143     /* Disable Capture Compare feature */
144     __LL_TMR_CC_DISABLE(Instance);
145 
146     /* Disable TMR export trigger event feature */
147     WRITE_REG(Instance->ETER, 0);
148 
149     /* Handle Something */
150     LL_TMR_MspDeInit(Instance);
151 
152     /* Return function status */
153     return LL_OK;
154 }
155 
156 /**
157   * @brief  Initializes the TMR MSP.
158   * @param  Instance TMR peripheral
159   * @return None
160   */
LL_TMR_MspInit(TMR_TypeDef * Instance)161 __WEAK void LL_TMR_MspInit(TMR_TypeDef *Instance)
162 {
163     /* Prevent unused argument(s) compilation warning */
164     LL_UNUSED(Instance);
165 
166     /* NOTE: This function should not be modified, when the callback is needed,
167              the LL_TMR_MspInit could be implemented in the user file
168      */
169 }
170 
171 /**
172   * @brief  DeInitializes the TMR MSP
173   * @param  Instance TMR peripheral
174   * @return None
175   */
LL_TMR_MspDeInit(TMR_TypeDef * Instance)176 __WEAK void LL_TMR_MspDeInit(TMR_TypeDef *Instance)
177 {
178     /* Prevent unused argument(s) compilation warning */
179     LL_UNUSED(Instance);
180 
181     /* NOTE: This function should not be modified, when the callback is needed,
182              the LL_TMR_MspDeInit could be implemented in the user file
183      */
184 }
185 
186 /**
187   * @}
188   */
189 
190 
191 /** @defgroup TMR_LL_Exported_Functions_Group2 TMR Peripheral Control functions
192   * @brief    TMR Peripheral Control functions
193 @verbatim
194   ===============================================================================
195                        ##### Peripheral Control functions #####
196   ===============================================================================
197   [..]
198     This section provides functions allowing to:
199     (+) TMR Input-Capture configure functions
200     (+) TMR Output-Compare configure functions
201 
202 @endverbatim
203   * @{
204   */
205 
206 /**
207   * @brief  User can use this function to reconfigure the TMR TimeBase unit
208   *         according to the specified parameters in the TMR_TB_InitTypeDef on runtime.
209   * @param  Instance TMR peripheral instance
210   * @param  Config TMR TimeBase Unit configuration structure
211   * @return status of the initialization
212   */
LL_TMR_TB_Config(TMR_TypeDef * Instance,TMR_TB_InitTypeDef * Config)213 LL_StatusETypeDef LL_TMR_TB_Config(TMR_TypeDef *Instance, TMR_TB_InitTypeDef *Config)
214 {
215     /* Check the parameters */
216     assert_param(IS_TMR_ALL_INSTANCE(Instance));
217     assert_param(Config != NULL);
218 
219     /* Set configuration to TimeBase unit */
220     TMR_TB_SetConfig(Instance, Config);
221 
222     /* Return function status */
223     return LL_OK;
224 }
225 
226 
227 /**
228   * @brief  User can use this function to reconfigure the TMR Input Capture feature
229   *         according to the specified parameters in the TMR_IC_InitTypeDef on runtime.
230   * @note   Use LL_TMR_CC_ENABLE() or LL_TMR_CC_DISABLE() macros to enable or disable
231   *         the Capture Compare feature.
232   * @param  Instance TMR peripheral
233   * @param  Config TMR Input Capture configuration structure
234   * @return status of the configuration
235   */
LL_TMR_IC_Config(TMR_TypeDef * Instance,TMR_IC_InitTypeDef * Config)236 LL_StatusETypeDef LL_TMR_IC_Config(TMR_TypeDef *Instance, TMR_IC_InitTypeDef *Config)
237 {
238     /* Check the parameters */
239     assert_param(IS_TMR_ALL_INSTANCE(Instance));
240     assert_param(Config != NULL);
241 
242     /* Disable CCE before configuration */
243     CLEAR_BIT(Instance->CCCR, TMR_CCCR_CCE);
244 
245     /* Set configuration for Input Capture feature */
246     TMR_IC_SetConfig(Instance, Config);
247 
248     /* Return function status */
249     return LL_OK;
250 }
251 
252 /**
253   * @brief  User can use this function to reconfigure the TMR Output Compare feature
254   *         according to the specified parameters in the TMR_OC_InitTypeDef on runtime.
255   * @note   Use LL_TMR_CC_ENABLE() or LL_TMR_CC_DISABLE() macros to enable or disable
256   *         the Capture Compare feature.
257   * @param  Instance  TMR peripheral
258   * @param  Config TMR Output Compare configuration structure.
259   * @return status of the configuration
260   */
LL_TMR_OC_Config(TMR_TypeDef * Instance,TMR_OC_InitTypeDef * Config)261 LL_StatusETypeDef LL_TMR_OC_Config(TMR_TypeDef *Instance, TMR_OC_InitTypeDef *Config)
262 {
263     /* Check the parameters */
264     assert_param(IS_TMR_ALL_INSTANCE(Instance));
265     assert_param(Config != NULL);
266 
267     /* Disable CCE before configuration */
268     CLEAR_BIT(Instance->CCCR, TMR_CCCR_CCE);
269 
270     /* Set configuration for Output Compare feature */
271     TMR_OC_SetConfig(Instance, Config);
272 
273     /* Return function status */
274     return LL_OK;
275 
276 }
277 
278 /**
279   * @brief  User can use this function to reconfigure the TMR Export Trigger Event feature
280   *         according to the specified parameters in the TMR_EXT_InitTypeDef on runtime.
281   * @param  Instance TMR peripheral
282   * @param  Config TMR Export Trigger configuration structure.
283   * @note   Please notice if user want to enable or disable the TMR events as the internal signal,
284   *         this configuration function should be called to config the specified events.
285   * @return status of the configuration
286   */
LL_TMR_EXT_Config(TMR_TypeDef * Instance,TMR_EXT_InitTypeDef * Config)287 LL_StatusETypeDef LL_TMR_EXT_Config(TMR_TypeDef *Instance, TMR_EXT_InitTypeDef *Config)
288 {
289     /* Check the parameters */
290     assert_param(IS_TMR_ALL_INSTANCE(Instance));
291     assert_param(Config != NULL);
292 
293     /* Set configuration for Export Trigger Event feature */
294     TMR_EXT_SetConfig(Instance, Config);
295 
296     /* Return function status */
297     return LL_OK;
298 }
299 
300 /**
301   * @}
302   */
303 
304 
305 /** @defgroup TMR_LL_Exported_Functions_Group3 TMR Input and Output operation functions
306   * @brief    TMR Input and Output operation functions
307 @verbatim
308   ===============================================================================
309                   ##### Input and Output operation functions #####
310   ===============================================================================
311   [..]
312     This section provides functions allowing to:
313     (+) TMR Start and Stop functions
314     (+) TMR Synchro start function
315     (+) TMR event software generate function
316 
317 @endverbatim
318   * @{
319   */
320 
321 /**
322   * @brief  Start the Timer.
323   * @param  Instance TMR peripheral
324   * @return LL status
325   */
LL_TMR_Start(TMR_TypeDef * Instance)326 LL_StatusETypeDef LL_TMR_Start(TMR_TypeDef *Instance)
327 {
328     /* Check the parameters */
329     assert_param(IS_TMR_ALL_INSTANCE(Instance));
330 
331     /* Start Counter*/
332     __LL_TMR_ENABLE(Instance);
333 
334     /* Return function status */
335     return LL_OK;
336 }
337 
338 /**
339   * @brief  Stop the Timer.
340   * @param  Instance TMR peripheral
341   * @return LL status
342   */
LL_TMR_Stop(TMR_TypeDef * Instance)343 LL_StatusETypeDef LL_TMR_Stop(TMR_TypeDef *Instance)
344 {
345     /* Check the parameters */
346     assert_param(IS_TMR_ALL_INSTANCE(Instance));
347 
348     /* Stop Counter */
349     __LL_TMR_DISABLE(Instance);
350 
351     /* Return function status */
352     return LL_OK;
353 }
354 
355 /**
356   * @brief  Start the timer with interrupt enabled
357   * @param  Instance TMR peripheral
358   * @return LL status
359   */
LL_TMR_Start_IT(TMR_TypeDef * Instance)360 LL_StatusETypeDef LL_TMR_Start_IT(TMR_TypeDef *Instance)
361 {
362     /* Check the parameters */
363     assert_param(IS_TMR_ALL_INSTANCE(Instance));
364 
365     if ((Instance->CR & TMR_CR_UDIS_Msk) != TMR_CR_UDIS) {
366         /* TMR Update Interrupt Enable if Update event is enabled */
367         __LL_TMR_IT_ENABLE(Instance, TMR_IT_UIE);
368     }
369 
370     /* Check if Capture Compare mode is enabled */
371     if ((Instance->CCCR & TMR_CCCR_CCE_Msk) == TMR_CCCR_CCE) {
372         if ((Instance->CCCR & TMR_CCCR_CCS_Msk) == TMR_CCCR_CCS) {
373             /* Enable Input Capture interrupt source */
374             __LL_TMR_CC_IT_ENABLE(Instance, TMR_IT_ICIE | TMR_IT_ICOIE);
375         } else {
376             /* Enable Output Compare interrupt source */
377             __LL_TMR_CC_IT_ENABLE(Instance, TMR_IT_OCIE);
378         }
379     }
380 
381     /* TMR Counter Overflow Interrupt Enable */
382     __LL_TMR_IT_ENABLE(Instance, TMR_IT_OVIE);
383 
384     /* Start Counter */
385     __LL_TMR_ENABLE(Instance);
386 
387     /* Return function status */
388     return LL_OK;
389 }
390 
391 /**
392   * @brief  Stop the timer with interrupt disabled
393   * @param  Instance TMR peripheral
394   * @return LL status
395   */
LL_TMR_Stop_IT(TMR_TypeDef * Instance)396 LL_StatusETypeDef LL_TMR_Stop_IT(TMR_TypeDef *Instance)
397 {
398     /* Check the parameters */
399     assert_param(IS_TMR_ALL_INSTANCE(Instance));
400 
401     /* TMR Update and Counter Overflow Interrupt Disable */
402     __LL_TMR_IT_DISABLE(Instance, TMR_IT_UIE | TMR_IT_OVIE);
403 
404     /* Capture Compare interrupt disable */
405     __LL_TMR_CC_IT_DISABLE(Instance, (TMR_IT_ICIE     |
406                                       TMR_IT_ICOIE |
407                                       TMR_IT_OCIE));
408 
409     /* Stop Counter */
410     __LL_TMR_DISABLE(Instance);
411 
412     /* Return function status */
413     return LL_OK;
414 }
415 
416 /**
417   * @brief  Synchro Start the specifies timers.
418   * @param  TMRGRPx TMRGRP peripheral
419   *           @arg TMRGRP0: Group of LSTMRs(TMR0/1/2/3)
420   *           @arg TMRGRP1: Group of HSTMRs(TMR4/5/6/7)
421   * @param  SynchroMask Specifies timer masks to start synchronously. This parameter can be
422   *         any combination of @ref TMRGRP_Sync_definition :
423   *           @arg TMRGRP_SYNC_TMR0 : Select TMR0(specific to TMRGRP0)
424   *           @arg TMRGRP_SYNC_TMR1 : Select TMR1(specific to TMRGRP0)
425   *           @arg TMRGRP_SYNC_TMR2 : Select TMR2(specific to TMRGRP0)
426   *           @arg TMRGRP_SYNC_TMR3 : Select TMR3(specific to TMRGRP0)
427   *           @arg TMRGRP_SYNC_TMR4 : Select TMR4(specific to TMRGRP1)
428   *           @arg TMRGRP_SYNC_TMR5 : Select TMR5(specific to TMRGRP1)
429   *           @arg TMRGRP_SYNC_TMR6 : Select TMR6(specific to TMRGRP1)
430   *           @arg TMRGRP_SYNC_TMR7 : Select TMR7(specific to TMRGRP1)
431   *           @arg TMRGRP_SYNC_ALL  : Select all TMRs in TMRGRPx(x = 0 or 1)
432   * @note   Please notice that only timers in same group can be started synchronously.
433   *         For example for TMRGRP0, SynchroMask of the TMR0/1/2/3 will be started synchronously.
434   * @note   If user wants to use it with specifies timers' interrupt enabled, use __LL_TMR_IT_ENABLE()
435   *         and __LL_TMR_CC_IT_ENABLE() to enable the necessary interrupt sources before starting them.
436   * @return LL status
437   */
LL_TMR_Start_Synchro(TMRGRP_TypeDef * TMRGRPx,uint32_t SynchroMask)438 LL_StatusETypeDef LL_TMR_Start_Synchro(TMRGRP_TypeDef *TMRGRPx, uint32_t SynchroMask)
439 {
440     /* Check the parameters */
441     assert_param(IS_TMR_ALL_TMRGRP_INSTANCE(TMRGRPx));
442 
443     /* Start specifies timers synchronously */
444     WRITE_REG(TMRGRPx->SYNCR, SynchroMask);
445 
446     /* Return function status */
447     return LL_OK;
448 }
449 
450 /**
451   * @brief  Synchro Stop the specifies timers.
452   * @param  TMRGRPx TMRGRP peripheral
453   *           @arg TMRGRP0: Group of LSTMRs(TMR0/1/2/3)
454   *           @arg TMRGRP1: Group of HSTMRs(TMR4/5/6/7)
455   * @param  SynchroMask Specifies timer masks to stop synchronously. This parameter can be
456   *         any combination of @ref TMRGRP_Sync_definition :
457   *           @arg TMRGRP_SYNC_TMR0 : Select TMR0(specific to TMRGRP0)
458   *           @arg TMRGRP_SYNC_TMR1 : Select TMR1(specific to TMRGRP0)
459   *           @arg TMRGRP_SYNC_TMR2 : Select TMR2(specific to TMRGRP0)
460   *           @arg TMRGRP_SYNC_TMR3 : Select TMR3(specific to TMRGRP0)
461   *           @arg TMRGRP_SYNC_TMR4 : Select TMR4(specific to TMRGRP1)
462   *           @arg TMRGRP_SYNC_TMR5 : Select TMR5(specific to TMRGRP1)
463   *           @arg TMRGRP_SYNC_TMR6 : Select TMR6(specific to TMRGRP1)
464   *           @arg TMRGRP_SYNC_TMR7 : Select TMR7(specific to TMRGRP1)
465   *           @arg TMRGRP_SYNC_ALL  : Select all TMRs in TMRGRPx(x = 0 or 1)
466   * @note   Please notice that only timers in same group can be stopped synchronously.
467   *         For example for TMRGRP0, SynchroMask of the TMR0/1/2/3 will be stopped synchronously.
468   * @return LL status
469   */
LL_TMR_Stop_Synchro(TMRGRP_TypeDef * TMRGRPx,uint32_t SynchroMask)470 LL_StatusETypeDef LL_TMR_Stop_Synchro(TMRGRP_TypeDef *TMRGRPx, uint32_t SynchroMask)
471 {
472     /* Check the parameters */
473     assert_param(IS_TMR_ALL_TMRGRP_INSTANCE(TMRGRPx));
474 
475     /* Stop specifies timers synchronously */
476     WRITE_REG(TMRGRPx->SYNCR, SynchroMask << 4);
477 
478     /* Return function status */
479     return LL_OK;
480 }
481 
482 /**
483   * @brief  Generate a software event
484   * @param  Instance TMR peripheral
485   * @param  EventSource specifies the event source.
486   *          This parameter can be one of the following values in @ref TMR_Event_Source:
487   *            @arg TMR_EVENTSOURCE_UG: Reinitialize the counter and generates an update of the registers
488   *            @arg TMR_EVENTSOURCE_CCG: Generate a capture/compare event
489   * @return LL status
490   */
LL_TMR_EventGenerate(TMR_TypeDef * Instance,TMR_EventSRCETypeDef EventSource)491 LL_StatusETypeDef LL_TMR_EventGenerate(TMR_TypeDef *Instance, TMR_EventSRCETypeDef EventSource)
492 {
493     /* Check the TMR initiation struct allocation */
494     assert_param(IS_TMR_ALL_INSTANCE(Instance));
495 
496     /* Generation Timer Counter Update Event */
497     WRITE_REG(Instance->EGR, EventSource);
498 
499     /* Return function status */
500     return LL_OK;
501 }
502 
503 /**
504   * @}
505   */
506 
507 
508 /** @defgroup TMR_LL_Exported_Functions_Interrupt TMR Interrupt management
509   * @brief    TMR Initerrupt management
510 @verbatim
511   ===============================================================================
512                           ##### Initerrupt management #####
513   ===============================================================================
514   [..]
515       This section provides TMR interrupt handler and callback functions.
516 
517 @endverbatim
518   * @{
519   */
520 
521 /**
522   * @brief   This function handles TMR interrupts requests.
523   * @param   Instance TMR peripheral
524   * @return  None
525   */
LL_TMR_IRQHandler(TMR_TypeDef * Instance)526 void LL_TMR_IRQHandler(TMR_TypeDef *Instance)
527 {
528     /* Check the parameters */
529     assert_param(IS_TMR_ALL_INSTANCE(Instance));
530 
531     if ((__LL_TMR_IT_CHECK_SOURCE(Instance, TMR_IT_UIE) != RESET) &&
532         (__LL_TMR_GET_FLAG(Instance, TMR_FLAG_UIF) != RESET)) {
533         /* Clear the Update interrupt flag */
534         __LL_TMR_CLEAR_FLAG(Instance, TMR_FLAG_UIF);
535 
536         /* TMR Update Interrupt Callback */
537         LL_TMR_TB_UpdateCallback(Instance);
538     }
539 
540     if ((__LL_TMR_IT_CHECK_SOURCE(Instance, TMR_IT_OVIE) != RESET) &&
541         (__LL_TMR_GET_FLAG(Instance, TMR_FLAG_OVIF) != RESET)) {
542         /* Claer the OverFlow interrupt flag */
543         __LL_TMR_CLEAR_FLAG(Instance, TMR_FLAG_OVIF);
544 
545         /* TMR Counter Overflow Interrupt Callback */
546         LL_TMR_TB_OverflowCallback(Instance);
547     }
548 
549     if ((__LL_TMR_CC_IT_CHECK_SOURCE(Instance, TMR_IT_ICIE) != RESET) &&
550         (__LL_TMR_GET_FLAG(Instance, TMR_FLAG_ICIF) != RESET)) {
551         /* Claer the Capture interrupt flag */
552         __LL_TMR_CLEAR_FLAG(Instance, TMR_FLAG_ICIF);
553 
554         /* TMR Input Capture Captured Interrupt Callback */
555         LL_TMR_IC_CaptureCallback(Instance);
556     }
557 
558     if ((__LL_TMR_CC_IT_CHECK_SOURCE(Instance, TMR_IT_ICOIE) != RESET) &&
559         (__LL_TMR_GET_FLAG(Instance, TMR_FLAG_ICOIF) != RESET)) {
560         /* Claer the OverCapture interrupt flag */
561         __LL_TMR_CLEAR_FLAG(Instance, TMR_FLAG_ICOIF);
562 
563         /* Handle Something */
564         LL_TMR_IC_OverCaptureCallback(Instance);
565     }
566 
567     if ((__LL_TMR_CC_IT_CHECK_SOURCE(Instance, TMR_IT_OCIE) != RESET) &&
568         (__LL_TMR_GET_FLAG(Instance, TMR_FLAG_OCIF) != RESET)) {
569 
570         /* Claer the Compare interrupt flag */
571         __LL_TMR_CLEAR_FLAG(Instance, TMR_FLAG_OCIF);
572 
573         /* Handle Something*/
574         LL_TMR_OC_CompareMatchedCallback(Instance);
575     }
576 }
577 
578 /**
579   * @brief  TMR TimeBase unit (Counter) update interrupt callback function
580   * @param  Instance TMR peripheral
581   * @return None
582   */
LL_TMR_TB_UpdateCallback(TMR_TypeDef * Instance)583 __WEAK void LL_TMR_TB_UpdateCallback(TMR_TypeDef *Instance)
584 {
585     /* Prevent unused argument(s) compilation warning */
586     LL_UNUSED(Instance);
587 
588     /* NOTE: This function should not be modified, when the callback is needed,
589              the LL_TMR_TB_UpdateCallback could be implemented in the user file
590      */
591 }
592 
593 /**
594   * @brief  TMR TimeBase unit (Counter) overflow interrupt callback function
595   * @param  Instance TMR peripheral
596   * @return None
597   */
LL_TMR_TB_OverflowCallback(TMR_TypeDef * Instance)598 __WEAK void LL_TMR_TB_OverflowCallback(TMR_TypeDef *Instance)
599 {
600     /* Prevent unused argument(s) compilation warning */
601     LL_UNUSED(Instance);
602 
603     /* NOTE: This function should not be modified, when the callback is needed,
604              the LL_TMR_TB_OverflowCallback could be implemented in the user file
605      */
606 }
607 
608 /**
609   * @brief  TMR input capture interrupt callback function
610   * @param  Instance TMR peripheral
611   * @return None
612   */
LL_TMR_IC_CaptureCallback(TMR_TypeDef * Instance)613 __WEAK void LL_TMR_IC_CaptureCallback(TMR_TypeDef *Instance)
614 {
615     /* Prevent unused argument(s) compilation warning */
616     LL_UNUSED(Instance);
617 
618     /* NOTE: This function should not be modified, when the callback is needed,
619              the LL_TMR_IC_CaptureCallback could be implemented in the user file
620      */
621 }
622 
623 /**
624   * @brief  TMR input capture over-capture interrupt callback function
625   * @param  Instance TMR peripheral
626   * @return None
627   */
LL_TMR_IC_OverCaptureCallback(TMR_TypeDef * Instance)628 __WEAK void LL_TMR_IC_OverCaptureCallback(TMR_TypeDef *Instance)
629 {
630     /* Prevent unused argument(s) compilation warning */
631     LL_UNUSED(Instance);
632 
633     /* NOTE: This function should not be modified, when the callback is needed,
634              the LL_TMR_IC_OverCaptureCallback could be implemented in the user file
635      */
636 }
637 
638 /**
639   * @brief  TMR output compare matched interrupt callback function
640   * @param  Instance TMR peripheral
641   * @return None
642   */
LL_TMR_OC_CompareMatchedCallback(TMR_TypeDef * Instance)643 __WEAK void LL_TMR_OC_CompareMatchedCallback(TMR_TypeDef *Instance)
644 {
645     /* Prevent unused argument(s) compilation warning */
646     LL_UNUSED(Instance);
647 
648     /* NOTE: This function should not be modified, when the callback is needed,
649              the LL_TMR_OC_CompareMatchedCallback could be implemented in the user file
650      */
651 }
652 
653 /**
654   * @}
655   */
656 
657 /**
658   * @}
659   */
660 
661 
662 /* Private functions ---------------------------------------------------------*/
663 /** @addtogroup TMR_LL_Private_Functions
664   * @{
665   */
666 
667 /**
668   * @brief  Set Configuration to TimeBase Unit.
669   * @param  Instance TMR peripheral instance
670   * @param  Config TMR TimeBase Unit configuration structure
671   * @return None
672   */
TMR_TB_SetConfig(TMR_TypeDef * Instance,TMR_TB_InitTypeDef * Config)673 static void TMR_TB_SetConfig(TMR_TypeDef *Instance, TMR_TB_InitTypeDef *Config)
674 {
675     if (IS_TMR_LSTMR_INSTANCE(Instance)) {    /* Check if Low-Speed Timer instance */
676         assert_param(IS_TMR_LSTMR_PRESCALER(Config->Prescaler));
677         assert_param(IS_TMR_LSTMR_END_VAL(Config->EndValue));
678         assert_param(IS_TMR_LSTMR_START_VAL(Config->StartValue));
679     } else {    /* High-Speed Timer instance */
680         assert_param(IS_TMR_HSTMR_PRSCALER(Config->Prescaler));
681         assert_param(IS_TMR_HSTMR_END_VAL(Config->EndValue));
682         assert_param(IS_TMR_HSTMR_START_VAL(Config->StartValue));
683     }
684 
685     /* Set the Counter Start value*/
686     WRITE_REG(Instance->CSVR, Config->StartValue);
687 
688     /* Set the Counter End value*/
689     WRITE_REG(Instance->CEVR, Config->EndValue);
690 
691     /* Set the Prescaler value*/
692     WRITE_REG(Instance->PSCR, Config->Prescaler);
693 
694     /* Configures: Clock source, Auto-Reload preload, Continuous mode, Update enable and
695        Update request source */
696     WRITE_REG(Instance->CR, (Config->ClockSource | Config->AutoReloadPreload | Config->ContinuousMode |
697                              Config->UpdateSource | Config->UpdateEnable));
698 }
699 
700 /**
701   * @brief  Set Configuration for Input Capture feature.
702   * @param  Instance TMR peripheral instance
703   * @param  sConfig TMR Input Capture configuration structure
704   * @return None
705   */
TMR_IC_SetConfig(TMR_TypeDef * Instance,TMR_IC_InitTypeDef * sConfig)706 static void TMR_IC_SetConfig(TMR_TypeDef *Instance, TMR_IC_InitTypeDef *sConfig)
707 {
708     /* Check the parameters */
709     assert_param(IS_TMR_ALL_INSTANCE(Instance));
710 
711     /* Check if enable the input capture feature.
712        Note: To do that TMR clock source must be configured to internal source */
713     if ((sConfig->ICEnable == ENABLE) && (READ_BIT(Instance->CR, TMR_CR_CKSRC_Msk) == TMR_CLKSOURCE_INTERNAL)) {
714         assert_param(IS_TMR_ICFILTER(sConfig->ICFilter));
715 
716         /* Set Input Capture filter */
717         WRITE_REG(Instance->ICFR, sConfig->ICFilter);
718 
719         /* Configurate the TMRx_CCCR register */
720         MODIFY_REG(Instance->CCCR,
721                    (TMR_CCCR_ICSRC_Msk
722                     | TMR_CCCR_CCP_Msk),
723                    (TMR_CCCR_CCS
724                     | sConfig->ICSelection
725                     | sConfig->ICPolarity));
726 
727         /* Set CCE to enable the input-capture feature */
728         SET_BIT(Instance->CCCR, TMR_CCCR_CCE);
729     }
730 }
731 
732 /**
733   * @brief  Set Configuration for Output Compare feature.
734   * @param  Instance TMR peripheral instance
735   * @param  sConfig TMR Output Compare configuration structure
736   * @return None
737   */
TMR_OC_SetConfig(TMR_TypeDef * Instance,TMR_OC_InitTypeDef * sConfig)738 static void TMR_OC_SetConfig(TMR_TypeDef *Instance, TMR_OC_InitTypeDef *sConfig)
739 {
740     /* Check the parameters */
741     assert_param(IS_TMR_ALL_INSTANCE(Instance));
742 
743     /* Check if enable the output compare feature.
744        Note: To do that TMR clock source must be configured to internal source */
745     if ((sConfig->OCEnable == ENABLE) && (READ_BIT(Instance->CR, TMR_CR_CKSRC_Msk) == TMR_CLKSOURCE_INTERNAL)) {
746         if (IS_TMR_LSTMR_INSTANCE(Instance)) {
747             assert_param(IS_TMR_LSTMR_COMPARE_VAL(sConfig->OCValue));
748         } else {
749             assert_param(IS_TMR_HSTMR_COMPARE_VAL(sConfig->OCValue));
750         }
751 
752         /* Disable Output Preload feature before configuration */
753         CLEAR_BIT(Instance->CCCR, TMR_CCCR_OCPE);
754 
755         /* Set Compare Value */
756         WRITE_REG(Instance->CCR, sConfig->OCValue);
757 
758         /* Configurate the TMRx_CCCR register */
759         MODIFY_REG(Instance->CCCR,
760                    (TMR_CCCR_OCPE_Msk
761                     | TMR_CCCR_CCS_Msk
762                     | TMR_CCCR_OCM_Msk
763                     | TMR_CCCR_CCP_Msk),
764                    (sConfig->OCMode
765                     | sConfig->OCPolarity
766                     | sConfig->OCPreload));
767 
768         /* Set CCE to enable the input-capture feature */
769         SET_BIT(Instance->CCCR, TMR_CCCR_CCE);
770     }
771 }
772 
773 /**
774   * @brief  Set Configuration for TMR Export Trigger Event feature.
775   * @param  Instance TMR peripheral
776   * @param  Config TMR Export Trigger configuration structure.
777   * @return None
778   */
TMR_EXT_SetConfig(TMR_TypeDef * Instance,TMR_EXT_InitTypeDef * sConfig)779 static void TMR_EXT_SetConfig(TMR_TypeDef *Instance, TMR_EXT_InitTypeDef *sConfig)
780 {
781     /* Check the parameters */
782     assert_param(IS_TMR_ALL_INSTANCE(Instance));
783 
784     if (sConfig->ExtEnable == ENABLE) {
785         /* Configure the events */
786         MODIFY_REG(Instance->ETER,
787                    (TMR_ETER_CCTPW_Msk
788                     | TMR_ETER_UTPW_Msk
789                     | TMR_ETER_PWMOE_Msk
790                     | TMR_ETER_CCTE_Msk
791                     | TMR_ETER_UTE_Msk),
792                    ((0xFU << TMR_ETER_CCTPW_Pos) |
793                     (0xFU << TMR_ETER_UTPW_Pos)
794                     | sConfig->ExtPWMWave
795                     | sConfig->ExtCCTrigger
796                     | sConfig->ExtTRGOTrigger));
797     } else {
798         WRITE_REG(Instance->ETER, 0);
799     }
800 }
801 
802 /**
803   * @}
804   */
805 
806 
807 #endif /* LL_TMR_MODULE_ENABLED */
808 
809 
810 /**
811   * @}
812   */
813 
814 /**
815   * @}
816   */
817 
818 
819 /************************* (C) COPYRIGHT Tai-Action *****END OF FILE***********/
820 
821