]> git.friedersdorff.com Git - max/tmk_keyboard.git/blob - tool/mbed/mbed-sdk/libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F3XX/stm32f30x_hrtim.c
Squashed 'tmk_core/' changes from 7967731..b9e0ea0
[max/tmk_keyboard.git] / tool / mbed / mbed-sdk / libraries / mbed / targets / cmsis / TARGET_STM / TARGET_STM32F3XX / stm32f30x_hrtim.c
1 /**
2   ******************************************************************************
3   * @file    stm32f30x_hrtim.c
4   * @author  MCD Application Team
5   * @version V1.1.0
6   * @date    27-February-2014
7   * @brief   HRTIMx module driver.
8   *    
9   *          This file provides firmware functions to manage the following 
10   *          functionalities of the HRTIMx peripheral:
11   *           + Initialization/de-initialization methods
12   *           + I/O operation methods
13   *           + Peripheral Control methods 
14   *         
15   @verbatim
16 ================================================================================
17                     ##### <HRTIM specific features> #####
18 ================================================================================
19            
20   [..] < HRTIM introduction: 
21        (#) The high-resolution timer can generate up to 10 digital signals with
22            highly accurate timings.
23            It is primarily intended to drive power conversion systems such as 
24            switch mode power supplies or lighting systems, 
25            but can be of general purpose usage, whenever a very fine timing 
26            resolution is expected.
27
28        (#) Its modular architecture allows to generate either independent or 
29            coupled waveforms. 
30            The wave-shape is defined by self-contained timings 
31            (using counters and compare units) and a broad range of external events,
32            such as analog or digital feedbacks and synchronisation signals. 
33            This allows to produce a large variety of control signal (PWM, phase-shifted,
34            constant Ton,...) and address most of conversion topologies.
35
36        (#) For control and monitoring purposes, the timer has also timing measure 
37            capabilities and links to built-in ADC and DAC converters. 
38            Last, it features light-load management mode and is able to handle 
39            various fault schemes for safe shut-down purposes.
40                  
41    
42             ##### How to use this driver #####
43 ================================================================================
44         [..] This driver provides functions to configure and program the HRTIM 
45         of all stm32f33x devices.
46         These functions are split in 9 groups: 
47      
48         (#) HRTIM Simple TimeBase management: this group includes all needed functions 
49             to configure the HRTIM Timebase unit:
50                  (++) Initializes the HRTIMx timer in simple time base mode 
51                  (++) Start/Stop the time base generation
52                  (++) Deinitialize the HRTIM peripheral  
53     
54                    
55        (#) HRTIM simple Output Compare management: this group includes all needed 
56            functions to configure the Compare unit used in Output compare mode: 
57                  (++) Initializes the HRTIMx timer time base unit 
58                  (++) Configure the compare unit in in simple Output Compare mode
59                  (++) Start/Stop the Output compare generation    
60                     
61        (#) HRTIM simple PWM management: this group includes all needed 
62            functions to configure the Compare unit used in PWM mode: 
63                  (++) Initializes the HRTIMx timer time base unit 
64                  (++) Configure the compare unit in in simple PWM mode
65                  (++) Start/Stop the PWM generation      
66                      
67        (#) HRTIM simple Capture management: this group includes all needed 
68            functions to configure the Capture unit used in Capture mode: 
69                  (++) Initializes the HRTIMx timer time base unit 
70                  (++) Configure the compare unit in in simple Capture mode
71                  (++) Start/Stop the Capture mode
72
73        (#) HRTIM simple One Pulse management: this group includes all needed 
74            functions to configure the Capture unit and Compare unit used in One Pulse mode: 
75                  (++) Initializes the HRTIMx timer time base unit 
76                  (++) Configure the compare unit and the capture unit in in simple One Pulse mode
77                  (++) Start/Stop the One Pulse mode generation 
78                    
79        (#) HRTIM Waveform management: this group includes all needed 
80            functions to configure the HRTIM possible waveform mode: 
81                  (++) Initializes the HRTIMx timer Master time base unit 
82                  (++) Initializes the HRTIMx timer Slaves time base unit
83                  (++) Configures the HRTIMx timer Compare unit  
84                  (++) Configures the HRTIMx Slave timer Capture unit 
85                  (++) Configures the HRTIMx timer Output unit 
86                  (++) Configures the HRTIMx timer DeadTime / Chopper / Burst features 
87                  (++) Configures the HRTIMx timer Fault / External event features 
88                  (++) Configures the HRTIMx timer Synchronization features: Internal/External connection, DACs,... 
89                  (++) Configures the HRTIMx timer Synchronization features: ADCs Triggers  
90                  (++) HRTIMx timer Outputs Start/Stop  
91                  (++) Start/Stop the HRTIMx Timer counters            
92                                
93         (#) HRTIM interrupts, DMA and flags management
94                  (++) Enable/Disable interrupt sources
95                  (++) Get flags status
96                  (++) Clear flags/ Pending bits
97                  (++) Enable/Disable DMA requests 
98                  (++) Configure DMA burst mode
99        
100         (#) TIM specific interface management, this group includes all 
101             needed functions to use the specific TIM interface:
102                  (++) HRTIMx timer DLL calibration      
103   
104   @endverbatim
105   ******************************************************************************
106   * @attention
107   *
108   * <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
109   *
110   * Redistribution and use in source and binary forms, with or without modification,
111   * are permitted provided that the following conditions are met:
112   *   1. Redistributions of source code must retain the above copyright notice,
113   *      this list of conditions and the following disclaimer.
114   *   2. Redistributions in binary form must reproduce the above copyright notice,
115   *      this list of conditions and the following disclaimer in the documentation
116   *      and/or other materials provided with the distribution.
117   *   3. Neither the name of STMicroelectronics nor the names of its contributors
118   *      may be used to endorse or promote products derived from this software
119   *      without specific prior written permission.
120   *
121   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
122   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
123   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
124   * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
125   * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
126   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
127   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
128   * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
129   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
130   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
131   *
132   ******************************************************************************  
133   */ 
134 /* Includes ------------------------------------------------------------------*/
135 #include "stm32f30x_hrtim.h"
136
137 /** @addtogroup STM32F30x_StdPeriph_Driver
138   * @{
139   */
140
141 /** @defgroup HRTIM 
142   * @brief HRTIM driver module
143   * @{
144   */
145
146 /* Private typedef -----------------------------------------------------------*/
147 /* Private define ------------------------------------------------------------*/
148 #define HRTIM_FLTR_FLTxEN (HRTIM_FLTR_FLT1EN |\
149                            HRTIM_FLTR_FLT2EN |\
150                            HRTIM_FLTR_FLT3EN |\
151                            HRTIM_FLTR_FLT4EN | \
152                            HRTIM_FLTR_FLT5EN)
153
154 #define HRTIM_TIMCR_TIMUPDATETRIGGER (HRTIM_TIMUPDATETRIGGER_MASTER  |\
155                                       HRTIM_TIMUPDATETRIGGER_TIMER_A |\
156                                       HRTIM_TIMUPDATETRIGGER_TIMER_B |\
157                                       HRTIM_TIMUPDATETRIGGER_TIMER_C |\
158                                       HRTIM_TIMUPDATETRIGGER_TIMER_D |\
159                                       HRTIM_TIMUPDATETRIGGER_TIMER_E)
160
161 #define HRTIM_TIM_OFFSET      (uint32_t)0x00000080
162 /* Private macro -------------------------------------------------------------*/
163 /* Private variables ---------------------------------------------------------*/
164 static uint32_t TimerIdxToTimerId[] = 
165 {
166   HRTIM_TIMERID_TIMER_A,
167   HRTIM_TIMERID_TIMER_B,
168   HRTIM_TIMERID_TIMER_C,
169   HRTIM_TIMERID_TIMER_D,
170   HRTIM_TIMERID_TIMER_E,
171   HRTIM_TIMERID_MASTER,
172 };
173
174 /* Private function prototypes -----------------------------------------------*/
175 /* Private functions ---------------------------------------------------------*/
176 static void HRTIM_MasterBase_Config(HRTIM_TypeDef* HRTIMx, HRTIM_BaseInitTypeDef* HRTIM_BaseInitStruc);
177 static void HRTIM_TimingUnitBase_Config(HRTIM_TypeDef * HRTIMx, uint32_t TimerIdx, HRTIM_BaseInitTypeDef* HRTIM_BaseInitStruct);
178 static void HRTIM_MasterWaveform_Config(HRTIM_TypeDef * HRTIMx, HRTIM_TimerInitTypeDef * TimerInit);
179 static void HRTIM_TimingUnitWaveform_Config(HRTIM_TypeDef * HRTIMx, 
180                                             uint32_t TimerIdx, 
181                                             HRTIM_TimerInitTypeDef * TimerInit);
182 static void HRTIM_CompareUnitConfig(HRTIM_TypeDef * HRTIMx,
183                                     uint32_t TimerIdx,
184                                     uint32_t CompareUnit,
185                                     HRTIM_CompareCfgTypeDef * CompareCfg);
186 static void HRTIM_CaptureUnitConfig(HRTIM_TypeDef * HRTIMx,
187                                     uint32_t TimerIdx,
188                                     uint32_t CaptureUnit,
189                                     uint32_t Event);
190 static void HRTIM_OutputConfig(HRTIM_TypeDef * HRTIMx,
191                                 uint32_t TimerIdx,
192                                 uint32_t Output,
193                                 HRTIM_OutputCfgTypeDef * OutputCfg);
194 static void HRTIM_ExternalEventConfig(HRTIM_TypeDef * HRTIMx,
195                                       uint32_t Event,
196                                       HRTIM_EventCfgTypeDef * EventCfg);
197 static void HRTIM_TIM_ResetConfig(HRTIM_TypeDef * HRTIMx,
198                                   uint32_t TimerIdx,
199                                   uint32_t Event);  
200   /** @defgroup HRTIM_Private_Functions
201   * @{
202   */
203
204 /** @defgroup HRTIM_Group1 Initialization/de-initialization methods 
205  *  @brief    Initialization and Configuration functions 
206  *
207 @verbatim    
208  ===============================================================================
209               ##### Initialization/de-initialization methods #####
210  ===============================================================================
211     [..]  This section provides functions allowing to:
212           (+)Initializes timer in basic time base mode
213           (+)Initializes timer in basic OC mode
214           (+)Initializes timer in basic PWM mode
215           (+)Initializes timer in basic Capture mode
216           (+)Initializes timer in One Pulse mode
217           (+)Initializes a timer operating in waveform mode
218           (+)De-initializes the HRTIMx timer
219  
220 @endverbatim
221   * @{
222   */
223
224 /**
225   * @brief  Initializes the HRTIMx timer in basic time base mode 
226   * @param  HRTIMx: pointer to HRTIMx peripheral
227   * @param  TimerIdx: Timer index
228   *                   This parameter can be one of the following values:
229   *                   @arg 0x0 for master timer
230   *                   @arg 0x1 to 0x5 for timers A to E
231   * @note   The time-base unit initialization parameters specify:
232   *           The timer counter operating mode (continuous, one shot)
233   *           The timer clock prescaler
234   *           The timer period 
235   *           The timer repetition counter.
236   * @retval None
237   */
238 void HRTIM_SimpleBase_Init(HRTIM_TypeDef* HRTIMx, uint32_t TimerIdx, HRTIM_BaseInitTypeDef* HRTIM_BaseInitStruct)
239 {
240   /* Check the parameters */
241   assert_param(IS_HRTIM_TIMERINDEX(TimerIdx));
242   assert_param(IS_HRTIM_MODE(HRTIM_BaseInitStruct->Mode));
243    
244   if (TimerIdx == HRTIM_TIMERINDEX_MASTER)
245   {
246     /* Configure master timer */
247     HRTIM_MasterBase_Config(HRTIMx, HRTIM_BaseInitStruct);
248   }
249   else
250   {
251     /* Configure timing unit */
252     HRTIM_TimingUnitBase_Config(HRTIMx, TimerIdx, HRTIM_BaseInitStruct);
253   }
254 }
255
256 /**
257   * @brief  De-initializes a timer operating in all mode 
258   * @param  HRTIMx: pointer to HRTIMx peripheral 
259   * @retval None
260   */
261 void HRTIM_DeInit(HRTIM_TypeDef* HRTIMx)
262 {
263   /* Check the parameters */
264     RCC_APB2PeriphResetCmd(RCC_APB2Periph_HRTIM1, ENABLE);
265     RCC_APB2PeriphResetCmd(RCC_APB2Periph_HRTIM1, DISABLE);  
266  }
267
268 /**
269   * @brief  Initializes the HRTIMx timer in basic output compare mode 
270   * @param  HRTIMx: pointer to HRTIMx peripheral
271   * @param  TimerIdx: Timer index
272   *                   This parameter can be one of the following values:
273   *                   @arg 0x1 to 0x5 for timers A to E
274   * @note   Initializes the time-base unit of the timer and prepare it to
275   *         operate in output compare mode
276   * @retval None
277   */
278 void HRTIM_SimpleOC_Init(HRTIM_TypeDef * HRTIMx, uint32_t TimerIdx, HRTIM_BaseInitTypeDef* HRTIM_BaseInitStruct)
279 {
280   /* Check the parameters */
281   assert_param(IS_HRTIM_TIMERINDEX(TimerIdx));
282   assert_param(IS_HRTIM_MODE(HRTIM_BaseInitStruct->Mode));
283    
284   /* Configure timing unit */
285   HRTIM_TimingUnitBase_Config(HRTIMx, TimerIdx, HRTIM_BaseInitStruct);
286 }
287
288 /**
289   * @brief  Initializes the HRTIMx timer in basic PWM mode 
290   * @param  HRTIMx: pointer to HRTIMx peripheral
291   * @param  TimerIdx: Timer index
292   *                   This parameter can be one of the following values:
293   *                   @arg 0x1 to 0x5 for timers A to E
294   * @note   Initializes the time-base unit of the timer and prepare it to
295   *         operate in capture mode
296   * @retval None
297   */
298 void HRTIM_SimplePWM_Init(HRTIM_TypeDef * HRTIMx, uint32_t TimerIdx, HRTIM_BaseInitTypeDef* HRTIM_BaseInitStruct)
299 {
300   /* Check the parameters */
301   assert_param(IS_HRTIM_TIMERINDEX(TimerIdx));
302   assert_param(IS_HRTIM_MODE(HRTIM_BaseInitStruct->Mode));
303   
304   /* Configure timing unit */
305   HRTIM_TimingUnitBase_Config(HRTIMx, TimerIdx, HRTIM_BaseInitStruct);
306 }
307
308 /**
309   * @brief  Initializes a timer operating in basic capture mode 
310   * @param  HRTIMx: pointer to HRTIMx peripheral
311   * @param  TimerIdx: Timer index
312   *                   This parameter can be one of the following values:
313   *                   @arg 0x1 to 0x5 for timers A to E 
314   * @retval None
315   */
316 void HRTIM_SimpleCapture_Init(HRTIM_TypeDef * HRTIMx, uint32_t TimerIdx, HRTIM_BaseInitTypeDef* HRTIM_BaseInitStruct)
317 {
318   /* Check the parameters */
319   assert_param(IS_HRTIM_TIMERINDEX(TimerIdx));
320   assert_param(IS_HRTIM_MODE(HRTIM_BaseInitStruct->Mode));
321   
322   /* Configure timing unit */
323   HRTIM_TimingUnitBase_Config(HRTIMx, TimerIdx, HRTIM_BaseInitStruct);
324 }
325
326 /**
327   * @brief  Initializes the HRTIMx timer in basic one pulse mode 
328   * @param  HRTIMx: pointer to  HRTIMx peripheral
329   * @param  TimerIdx: Timer index
330   *                   This parameter can be one of the following values:
331   *                   @arg 0x1 to 0x5 for timers A to E
332   * @note   Initializes the time-base unit of the timer and prepare it to
333   *         operate in one pulse mode. In this mode the counter operates
334   *         in single shot mode (retriggerable or not)
335   * @retval None
336   */
337 void HRTIM_SimpleOnePulse_Init(HRTIM_TypeDef * HRTIMx, uint32_t TimerIdx, HRTIM_BaseInitTypeDef* HRTIM_BaseInitStruct)
338 {
339   /* Check the parameters */
340   assert_param(IS_HRTIM_TIMERINDEX(TimerIdx));
341   assert_param(IS_HRTIM_MODE(HRTIM_BaseInitStruct->Mode));
342   
343   /* Configure timing unit */
344   HRTIM_TimingUnitBase_Config(HRTIMx, TimerIdx, HRTIM_BaseInitStruct);
345 }
346
347 /**
348   * @brief  Initializes a timer operating in waveform mode 
349   * @param  HRTIMx: pointer to HRTIMx peripheral
350   * @param  TimerIdx: Timer index
351   *                   This parameter can be one of the following values:
352   *                   @arg 0x0 for master timer
353   *                   @arg 0x1 to 0x5 for timers A to E 
354   * @param  pTimerInit: pointer to the timer initialization data structure
355   * @retval None
356   */
357 void HRTIM_Waveform_Init(HRTIM_TypeDef * HRTIMx,
358                                          uint32_t TimerIdx,
359                                          HRTIM_BaseInitTypeDef* HRTIM_BaseInitStruct,
360                                          HRTIM_TimerInitTypeDef* HRTIM_TimerInitStruct)
361 {
362   /* Check the parameters */
363   assert_param(IS_HRTIM_HALFMODE(HRTIM_TimerInitStruct->HalfModeEnable));
364   assert_param(IS_HRTIM_SYNCSTART(HRTIM_TimerInitStruct->StartOnSync));
365   assert_param(IS_HRTIM_SYNCRESET(HRTIM_TimerInitStruct->ResetOnSync));
366   assert_param(IS_HRTIM_DACSYNC(HRTIM_TimerInitStruct->DACSynchro));
367   assert_param(IS_HRTIM_PRELOAD(HRTIM_TimerInitStruct->PreloadEnable));
368   assert_param(IS_HRTIM_TIMERBURSTMODE(HRTIM_TimerInitStruct->BurstMode));
369   assert_param(IS_HRTIM_UPDATEONREPETITION(HRTIM_TimerInitStruct->RepetitionUpdate));
370  
371   if (TimerIdx == HRTIM_TIMERINDEX_MASTER)
372   {
373     /* Check parameters */
374     assert_param(IS_HRTIM_UPDATEGATING_MASTER(HRTIM_TimerInitStruct->UpdateGating));  
375     
376     /* Configure master timer */
377     HRTIM_MasterBase_Config(HRTIMx, HRTIM_BaseInitStruct);
378     HRTIM_MasterWaveform_Config(HRTIMx, HRTIM_TimerInitStruct);
379   }
380   else
381   {
382     /* Check parameters */
383     assert_param(IS_HRTIM_UPDATEGATING_TIM(HRTIM_TimerInitStruct->UpdateGating));  
384     
385     /* Configure timing unit */
386     HRTIM_TimingUnitBase_Config(HRTIMx, TimerIdx, HRTIM_BaseInitStruct);
387     HRTIM_TimingUnitWaveform_Config(HRTIMx, TimerIdx, HRTIM_TimerInitStruct);
388   }
389 }
390
391 /**
392   * @}
393   */
394
395 /** @defgroup HRTIM_Group2 I/O operation methods 
396  *  @brief   Data transfers functions 
397  *
398 @verbatim   
399  ===============================================================================
400                       ##### IO operation methods #####
401  ===============================================================================  
402     [..]
403     This subsection provides a set of functions allowing to manage the HRTIMx data 
404     transfers.
405     (+) Starts the DLL calibration.
406     (+) Starts / stops the counter of a timer operating in basic time base mode
407     (+) Starts / stops the output compare signal generation on the designed timer output
408     (+) Starts / stops the PWM output signal generation on the designed timer output
409     (+) Enables / disables a basic capture on the designed capture unit
410
411 @endverbatim
412   * @{
413   */
414
415 /**
416   * @brief  Starts the DLL calibration
417   * @param  HRTIMx: pointer to HRTIMx peripheral
418   * @param  CalibrationRate: DLL calibration period
419   *                    This parameter can be one of the following values:
420   *                    @arg HRTIM_CALIBRATIONRATE_7300: 7.3 ms
421   *                    @arg HRTIM_CALIBRATIONRATE_910: 910 us
422   *                    @arg HRTIM_CALIBRATIONRATE_114: 114 us
423   *                    @arg HRTIM_CALIBRATIONRATE_14: 14 us
424   * @retval None
425   */
426 void HRTIM_DLLCalibrationStart(HRTIM_TypeDef * HRTIMx, uint32_t CalibrationRate)
427 {
428   uint32_t HRTIM_dllcr;
429   
430    /* Check the parameters */
431   assert_param(IS_HRTIM_CALIBRATIONRATE(CalibrationRate));
432
433   /* Configure DLL Calibration */
434   HRTIM_dllcr = (HRTIMx->HRTIM_COMMON).DLLCR;
435   
436   /* Set the Calibration rate */
437   HRTIM_dllcr &= ~(HRTIM_DLLCR_CALRTE);
438   HRTIM_dllcr |= CalibrationRate;
439     
440   /* Start DLL calibration */
441    HRTIM_dllcr |= HRTIM_DLLCR_CAL;
442                
443   /* Update HRTIMx register */
444   (HRTIMx->HRTIM_COMMON).DLLCR = HRTIM_dllcr;
445   
446 }
447 /**
448   * @brief  Starts the counter of a timer operating in basic time base mode
449   * @param  HRTIMx: pointer to HRTIM peripheral
450   * @param  TimerIdx: Timer index
451   *                   This parameter can be one of the following values:
452   *                   @arg 0x5 for master timer
453   *                   @arg 0x0 to 0x4 for timers A to E 
454   * @retval None
455   */
456 void HRTIM_SimpleBaseStart(HRTIM_TypeDef * HRTIMx, uint32_t TimerIdx)
457 {  
458    /* Check the parameters */
459   assert_param(IS_HRTIM_TIMERINDEX(TimerIdx));
460   
461   /* Enable the timer counter */
462   __HRTIM_ENABLE(HRTIMx, TimerIdxToTimerId[TimerIdx]);
463 }
464
465 /**
466   * @brief  Stops the counter of a timer operating in basic time base mode
467   * @param  HRTIMx: pointer to HRTIM peripheral
468   * @param  TimerIdx: Timer index
469   *                   This parameter can be one of the following values:
470   *                   @arg 0x5 for master timer
471   *                   @arg 0x0 to 0x4 for timers A to E 
472   * @retval None
473   */
474 void HRTIM_SimpleBaseStop(HRTIM_TypeDef * HRTIMx, uint32_t TimerIdx)
475 {
476    /* Check the parameters */
477   assert_param(IS_HRTIM_TIMERINDEX(TimerIdx)); 
478   
479   /* Disable the timer counter */
480   __HRTIM_DISABLE(HRTIMx, TimerIdxToTimerId[TimerIdx]);
481 }
482
483 /**
484   * @brief  Starts the output compare signal generation on the designed timer output 
485   * @param  HRTIMx: pointer to HRTIM peripheral
486   * @param  TimerIdx: Timer index
487   *                   This parameter can be one of the following values:
488   *                   @arg 0x0 to 0x4 for timers A to E 
489   * @param  OCChannel: Timer output
490   *                    This parameter can be one of the following values:
491   *                    @arg HRTIM_OUTPUT_TA1: Timer A - Output 1
492   *                    @arg HRTIM_OUTPUT_TA2: Timer A - Output 2
493   *                    @arg HRTIM_OUTPUT_TB1: Timer B - Output 1
494   *                    @arg HRTIM_OUTPUT_TB2: Timer B - Output 2
495   *                    @arg HRTIM_OUTPUT_TC1: Timer C - Output 1
496   *                    @arg HRTIM_OUTPUT_TC2: Timer C - Output 2
497   *                    @arg HRTIM_OUTPUT_TD1: Timer D - Output 1
498   *                    @arg HRTIM_OUTPUT_TD2: Timer D - Output 2
499   *                    @arg HRTIM_OUTPUT_TE1: Timer E - Output 1
500   *                    @arg HRTIM_OUTPUT_TE2: Timer E - Output 2
501   * @retval None
502   */
503 void HRTIM_SimpleOCStart(HRTIM_TypeDef * HRTIMx,
504                                          uint32_t TimerIdx,
505                                          uint32_t OCChannel)
506 {
507    /* Check the parameters */
508   assert_param(IS_HRTIM_TIMER_OUTPUT(TimerIdx, OCChannel));
509   
510   /* Enable the timer output */
511    (HRTIMx->HRTIM_COMMON).OENR |= OCChannel;
512        
513     /* Enable the timer counter */
514   __HRTIM_ENABLE(HRTIMx, TimerIdxToTimerId[TimerIdx]);
515   
516 }
517
518 /**
519   * @brief  Stops the output compare signal generation on the designed timer output 
520   * @param  HRTIMx: pointer to HRTIM peripheral
521   * @param  TimerIdx: Timer index
522   *                   This parameter can be one of the following values:
523   *                   @arg 0x0 to 0x4 for timers A to E 
524   * @param  OCChannel: Timer output
525   *                    This parameter can be one of the following values:
526   *                    @arg HRTIM_OUTPUT_TA1: Timer A - Output 1
527   *                    @arg HRTIM_OUTPUT_TA2: Timer A - Output 2
528   *                    @arg HRTIM_OUTPUT_TB1: Timer B - Output 1
529   *                    @arg HRTIM_OUTPUT_TB2: Timer B - Output 2
530   *                    @arg HRTIM_OUTPUT_TC1: Timer C - Output 1
531   *                    @arg HRTIM_OUTPUT_TC2: Timer C - Output 2
532   *                    @arg HRTIM_OUTPUT_TD1: Timer D - Output 1
533   *                    @arg HRTIM_OUTPUT_TD2: Timer D - Output 2
534   *                    @arg HRTIM_OUTPUT_TE1: Timer E - Output 1
535   *                    @arg HRTIM_OUTPUT_TE2: Timer E - Output 2
536   * @retval None
537   */
538 void HRTIM_SimpleOCStop(HRTIM_TypeDef * HRTIMx,
539                                         uint32_t TimerIdx,
540                                         uint32_t OCChannel)
541 {
542    /* Check the parameters */
543   assert_param(IS_HRTIM_TIMER_OUTPUT(TimerIdx, OCChannel));
544   
545   /* Disable the timer output */
546   HRTIMx->HRTIM_COMMON.DISR |= OCChannel;
547     
548   /* Disable the timer counter */
549    __HRTIM_DISABLE(HRTIMx, TimerIdxToTimerId[TimerIdx]);
550 }
551
552 /**
553   * @brief  Starts the PWM output signal generation on the designed timer output
554   * @param  HRTIMx: pointer to HRTIM peripheral
555   * @param  TimerIdx: Timer index
556   *                   This parameter can be one of the following values:
557   *                   @arg 0x0 to 0x4 for timers A to E 
558   * @param  PWMChannel: Timer output
559   *                    This parameter can be one of the following values:
560   *                    @arg HRTIM_OUTPUT_TA1: Timer A - Output 1
561   *                    @arg HRTIM_OUTPUT_TA2: Timer A - Output 2
562   *                    @arg HRTIM_OUTPUT_TB1: Timer B - Output 1
563   *                    @arg HRTIM_OUTPUT_TB2: Timer B - Output 2
564   *                    @arg HRTIM_OUTPUT_TC1: Timer C - Output 1
565   *                    @arg HRTIM_OUTPUT_TC2: Timer C - Output 2
566   *                    @arg HRTIM_OUTPUT_TD1: Timer D - Output 1
567   *                    @arg HRTIM_OUTPUT_TD2: Timer D - Output 2
568   *                    @arg HRTIM_OUTPUT_TE1: Timer E - Output 1
569   *                    @arg HRTIM_OUTPUT_TE2: Timer E - Output 2
570   * @retval None
571   */
572 void HRTIM_SimplePWMStart(HRTIM_TypeDef * HRTIMx,
573                                           uint32_t TimerIdx,
574                                           uint32_t PWMChannel)
575 {
576    /* Check the parameters */
577   assert_param(IS_HRTIM_TIMER_OUTPUT(TimerIdx, PWMChannel));
578   
579   /* Enable the timer output */
580   HRTIMx->HRTIM_COMMON.OENR |= PWMChannel;
581     
582   /* Enable the timer counter */
583   __HRTIM_ENABLE(HRTIMx, TimerIdxToTimerId[TimerIdx]);
584 }
585
586 /**
587   * @brief  Stops the PWM output signal generation on the designed timer output
588   * @param  HRTIMx: pointer to HRTIM peripheral
589   * @param  TimerIdx: Timer index
590   *                   This parameter can be one of the following values:
591   *                   @arg 0x0 to 0x4 for timers A to E 
592   * @param  PWMChannel: Timer output
593   *                    This parameter can be one of the following values:
594   *                    @arg HRTIM_OUTPUT_TA1: Timer A - Output 1
595   *                    @arg HRTIM_OUTPUT_TA2: Timer A - Output 2
596   *                    @arg HRTIM_OUTPUT_TB1: Timer B - Output 1
597   *                    @arg HRTIM_OUTPUT_TB2: Timer B - Output 2
598   *                    @arg HRTIM_OUTPUT_TC1: Timer C - Output 1
599   *                    @arg HRTIM_OUTPUT_TC2: Timer C - Output 2
600   *                    @arg HRTIM_OUTPUT_TD1: Timer D - Output 1
601   *                    @arg HRTIM_OUTPUT_TD2: Timer D - Output 2
602   *                    @arg HRTIM_OUTPUT_TE1: Timer E - Output 1
603   *                    @arg HRTIM_OUTPUT_TE2: Timer E - Output 2
604   * @retval None
605   */
606 void HRTIM_SimplePWMStop(HRTIM_TypeDef * HRTIMx,
607                                          uint32_t TimerIdx,
608                                          uint32_t PWMChannel)
609 {
610    /* Check the parameters */
611   assert_param(IS_HRTIM_TIMER_OUTPUT(TimerIdx, PWMChannel));
612  
613   /* Disable the timer output */
614   HRTIMx->HRTIM_COMMON.DISR |= PWMChannel;
615     
616   /* Disable the timer counter */
617    __HRTIM_DISABLE(HRTIMx, TimerIdxToTimerId[TimerIdx]);
618 }
619
620 /**
621   * @brief  Enables a basic capture on the designed capture unit
622   * @param  HRTIMx: pointer to HRTIM peripheral
623   * @param  TimerIdx: Timer index
624   *                   This parameter can be one of the following values:
625   *                   @arg 0x0 to 0x4 for timers A to E 
626   * @param  CaptureChannel: Timer output
627   *                    This parameter can be one of the following values: 
628   *                    @arg HRTIM_CAPTUREUNIT_1: Capture unit 1
629   *                    @arg HRTIM_CAPTUREUNIT_2: Capture unit 2
630   * @retval None
631   * @note  The external event triggering the capture is available for all timing 
632   *        units. It can be used directly and is active as soon as the timing 
633   *        unit counter is enabled.
634   */
635 void HRTIM_SimpleCaptureStart(HRTIM_TypeDef * HRTIMx,
636                                               uint32_t TimerIdx,
637                                               uint32_t CaptureChannel)
638 {
639   /* Enable the timer counter */
640   __HRTIM_ENABLE(HRTIMx, TimerIdxToTimerId[TimerIdx]);
641
642 }
643
644 /**
645   * @brief  Disables a basic capture on the designed capture unit 
646   * @param  HRTIMx: pointer to HRTIMx peripheral
647   * @param  TimerIdx: Timer index
648   *                   This parameter can be one of the following values:
649   *                   @arg 0x0 to 0x4 for timers A to E 
650   * @param  CaptureChannel: Timer output
651   *                    This parameter can be one of the following values: 
652   *                    @arg HRTIM_CAPTUREUNIT_1: Capture unit 1
653   *                    @arg HRTIM_CAPTUREUNIT_2: Capture unit 2
654   * @retval None
655   */
656 void HRTIM_SimpleCaptureStop(HRTIM_TypeDef * HRTIMx,
657                                              uint32_t TimerIdx,
658                                              uint32_t CaptureChannel)
659 {
660    /* Check the parameters */
661   assert_param(IS_HRTIM_TIMING_UNIT(TimerIdx));
662   assert_param(IS_HRTIM_CAPTUREUNIT(CaptureChannel));
663     
664   /* Set the capture unit trigger */
665   switch (CaptureChannel)
666   {
667     case HRTIM_CAPTUREUNIT_1:
668     {
669       HRTIMx->HRTIM_TIMERx[TimerIdx].CPT1xCR = HRTIM_CAPTURETRIGGER_NONE;
670     }
671     break;
672     case HRTIM_CAPTUREUNIT_2:
673     {
674       HRTIMx->HRTIM_TIMERx[TimerIdx].CPT2xCR = HRTIM_CAPTURETRIGGER_NONE;
675     }
676     break;
677     default:
678     break;  
679   }
680   
681   /* Disable the timer counter */
682   if ((HRTIMx->HRTIM_TIMERx[TimerIdx].CPT1xCR == HRTIM_CAPTURETRIGGER_NONE) &&
683       (HRTIMx->HRTIM_TIMERx[TimerIdx].CPT2xCR == HRTIM_CAPTURETRIGGER_NONE))
684   {
685     __HRTIM_DISABLE(HRTIMx, TimerIdxToTimerId[TimerIdx]);
686   }
687   
688 }
689
690 /**
691   * @brief  Enables the basic one pulse signal generation on the designed output 
692   * @param  HRTIMx: pointer to HRTIMx peripheral
693   * @param  TimerIdx: Timer index
694   *                   This parameter can be one of the following values:
695   *                   @arg 0x0 to 0x4 for timers A to E 
696   * @param  OnePulseChannel: Timer output
697   *                    This parameter can be one of the following values:
698   *                    @arg HRTIM_OUTPUT_TA1: Timer A - Output 1
699   *                    @arg HRTIM_OUTPUT_TA2: Timer A - Output 2
700   *                    @arg HRTIM_OUTPUT_TB1: Timer B - Output 1
701   *                    @arg HRTIM_OUTPUT_TB2: Timer B - Output 2
702   *                    @arg HRTIM_OUTPUT_TC1: Timer C - Output 1
703   *                    @arg HRTIM_OUTPUT_TC2: Timer C - Output 2
704   *                    @arg HRTIM_OUTPUT_TD1: Timer D - Output 1
705   *                    @arg HRTIM_OUTPUT_TD2: Timer D - Output 2
706   *                    @arg HRTIM_OUTPUT_TE1: Timer E - Output 1
707   *                    @arg HRTIM_OUTPUT_TE2: Timer E - Output 2
708   * @retval None
709   */
710 void HRTIM_SimpleOnePulseStart(HRTIM_TypeDef * HRTIMx,
711                                                 uint32_t TimerIdx,
712                                                 uint32_t OnePulseChannel)
713 {
714    /* Check the parameters */
715   assert_param(IS_HRTIM_TIMER_OUTPUT(TimerIdx, OnePulseChannel));
716   
717   /* Enable the timer output */
718   HRTIMx->HRTIM_COMMON.OENR |= OnePulseChannel;
719     
720   /* Enable the timer counter */
721   __HRTIM_ENABLE(HRTIMx, TimerIdxToTimerId[TimerIdx]);
722 }
723
724 /**
725   * @brief  Disables the basic one pulse signal generation on the designed output 
726   * @param  HRTIMx: pointer to HRTIMx peripheral
727   * @param  TimerIdx: Timer index
728   *                   This parameter can be one of the following values:
729   *                   @arg 0x0 to 0x4 for timers A to E 
730   * @param  OnePulseChannel: Timer output
731   *                    This parameter can be one of the following values:
732   *                    @arg HRTIM_OUTPUT_TA1: Timer A - Output 1
733   *                    @arg HRTIM_OUTPUT_TA2: Timer A - Output 2
734   *                    @arg HRTIM_OUTPUT_TB1: Timer B - Output 1
735   *                    @arg HRTIM_OUTPUT_TB2: Timer B - Output 2
736   *                    @arg HRTIM_OUTPUT_TC1: Timer C - Output 1
737   *                    @arg HRTIM_OUTPUT_TC2: Timer C - Output 2
738   *                    @arg HRTIM_OUTPUT_TD1: Timer D - Output 1
739   *                    @arg HRTIM_OUTPUT_TD2: Timer D - Output 2
740   *                    @arg HRTIM_OUTPUT_TE1: Timer E - Output 1
741   *                    @arg HRTIM_OUTPUT_TE2: Timer E - Output 2
742   * @retval None
743   */
744 void HRTIM_SimpleOnePulseStop(HRTIM_TypeDef * HRTIMx,
745                                               uint32_t TimerIdx,
746                                               uint32_t OnePulseChannel)
747 {
748    /* Check the parameters */
749   assert_param(IS_HRTIM_TIMER_OUTPUT(TimerIdx, OnePulseChannel));
750    
751   /* Disable the timer output */
752   HRTIMx->HRTIM_COMMON.DISR |= OnePulseChannel;
753   
754   /* Disable the timer counter */
755   __HRTIM_DISABLE(HRTIMx, TimerIdxToTimerId[TimerIdx]);
756 }
757
758 /**
759   * @brief  Starts the counter of the designated timer(s) operating in waveform mode
760   *         Timers can be combined (ORed) to allow for simultaneous counter start
761   * @param  HRTIMx: pointer to HRTIMx peripheral
762   * @param  TimersToStart: Timer counter(s) to start
763   *                   This parameter can be any combination of the following values:
764   *                   @arg HRTIM_TIMERID_MASTER 
765   *                   @arg HRTIM_TIMERID_TIMER_A 
766   *                   @arg HRTIM_TIMERID_TIMER_B 
767   *                   @arg HRTIM_TIMERID_TIMER_C 
768   *                   @arg HRTIM_TIMERID_TIMER_D 
769   *                   @arg HRTIM_TIMERID_TIMER_E 
770   * @retval None
771   */
772 void HRTIM_WaveformCounterStart(HRTIM_TypeDef * HRTIMx,
773                                                  uint32_t TimersToStart)
774
775    /* Enable timer(s) counter */
776    HRTIMx->HRTIM_MASTER.MCR |= TimersToStart;
777 }
778
779 /**
780   * @brief  Stops the counter of the designated timer(s) operating in waveform mode
781   *         Timers can be combined (ORed) to allow for simultaneous counter stop
782   * @param  HRTIMx: pointer to HRTIMx peripheral
783   * @param  TimersToStop: Timer counter(s) to stop
784   *                   This parameter can be any combination of the following values:
785   *                   @arg HRTIM_TIMER_MASTER 
786   *                   @arg HRTIM_TIMER_A 
787   *                   @arg HRTIM_TIMER_B 
788   *                   @arg HRTIM_TIMER_C 
789   *                   @arg HRTIM_TIMER_D 
790   *                   @arg HRTIM_TIMER_E 
791   * @retval None
792   */
793 void HRTIM_WaveformCounterStop(HRTIM_TypeDef * HRTIMx,
794                                                 uint32_t TimersToStop)
795 {
796   /* Disable timer(s) counter */
797   HRTIMx->HRTIM_MASTER.MCR &= ~TimersToStop;
798 }
799
800 /**
801   * @brief  Enables the generation of the waveform signal on the designated output(s)
802   *         Outputs can be combined (ORed) to allow for simultaneous output enabling
803   * @param  HRTIMx: pointer to HRTIMx peripheral
804   * @param  OutputsToStart: Timer output(s) to enable
805   *                    This parameter can be any combination of the following values:
806   *                    @arg HRTIM_OUTPUT_TA1: Timer A - Output 1
807   *                    @arg HRTIM_OUTPUT_TA2: Timer A - Output 2
808   *                    @arg HRTIM_OUTPUT_TB1: Timer B - Output 1
809   *                    @arg HRTIM_OUTPUT_TB2: Timer B - Output 2
810   *                    @arg HRTIM_OUTPUT_TC1: Timer C - Output 1
811   *                    @arg HRTIM_OUTPUT_TC2: Timer C - Output 2
812   *                    @arg HRTIM_OUTPUT_TD1: Timer D - Output 1
813   *                    @arg HRTIM_OUTPUT_TD2: Timer D - Output 2
814   *                    @arg HRTIM_OUTPUT_TE1: Timer E - Output 1
815   *                    @arg HRTIM_OUTPUT_TE2: Timer E - Output 2
816   * @retval None
817   */
818 void HRTIM_WaveformOutputStart(HRTIM_TypeDef * HRTIMx,
819                                                 uint32_t OutputsToStart)
820 {
821   /* Enable the HRTIM outputs */
822   HRTIMx->HRTIM_COMMON.OENR = OutputsToStart;
823 }
824
825 /**
826   * @brief  Disables the generation of the waveform signal on the designated output(s)
827   *         Outputs can be combined (ORed) to allow for simultaneous output disabling
828   * @param  HRTIMx: pointer to HRTIMx peripheral
829   * @param  OutputsToStop: Timer output(s) to disable
830   *                    This parameter can be any combination of the following values:
831   *                    @arg HRTIM_OUTPUT_TA1: Timer A - Output 1
832   *                    @arg HRTIM_OUTPUT_TA2: Timer A - Output 2
833   *                    @arg HRTIM_OUTPUT_TB1: Timer B - Output 1
834   *                    @arg HRTIM_OUTPUT_TB2: Timer B - Output 2
835   *                    @arg HRTIM_OUTPUT_TC1: Timer C - Output 1
836   *                    @arg HRTIM_OUTPUT_TC2: Timer C - Output 2
837   *                    @arg HRTIM_OUTPUT_TD1: Timer D - Output 1
838   *                    @arg HRTIM_OUTPUT_TD2: Timer D - Output 2
839   *                    @arg HRTIM_OUTPUT_TE1: Timer E - Output 1
840   *                    @arg HRTIM_OUTPUT_TE2: Timer E - Output 2
841   * @retval None
842   */
843 void HRTIM_WaveformOutputStop(HRTIM_TypeDef * HRTIMx,
844                                                uint32_t OutputsToStop)
845 {
846   /* Disable the HRTIM outputs */
847   HRTIMx->HRTIM_COMMON.DISR = OutputsToStop;
848 }
849
850 /**
851   * @brief  Enables or disables the Master and slaves interrupt request
852   * @param  HRTIMx: pointer to HRTIMx peripheral
853   * @param  TimerIdx: Timer index
854   *                   This parameter can be one of the following values:
855   *                   @arg 0x0 to 0x4 for timers A to E 
856   * @param  HRTIM_IT: specifies the HRTIM interrupts sources to be enabled or disabled.
857   *          This parameter can be any combination of the following values:
858   *            @arg HRTIM_MASTER_IT_MCMP1: Master compare 1 interrupt source
859   *            @arg HRTIM_MASTER_IT_MCMP2: Master compare 2 interrupt source
860   *            @arg HRTIM_MASTER_IT_MCMP3: Master compare 3 interrupt Interrupt source
861   *            @arg HRTIM_MASTER_IT_MCMP4: Master compare 4 Interrupt source
862   *            @arg HRTIM_MASTER_IT_MREP: Master Repetition Interrupt source
863   *            @arg HRTIM_MASTER_IT_SYNC: Synchronization input Interrupt source
864   *            @arg HRTIM_MASTER_IT_MUPD: Master update Interrupt source
865   *            @arg HRTIM_TIM_IT_CMP1: Timer compare 1 Interrupt source
866   *            @arg HRTIM_TIM_IT_CMP2: Timer compare 2 Interrupt source
867   *            @arg HRTIM_TIM_IT_CMP3: Timer compare 3 Interrupt source
868   *            @arg HRTIM_TIM_IT_CMP4: Timer compare 4 Interrupt source
869   *            @arg HRTIM_TIM_IT_REP: Timer repetition Interrupt source
870   *            @arg HRTIM_TIM_IT_UPD: Timer update Interrupt source
871   *            @arg HRTIM_TIM_IT_CPT1: Timer capture 1 Interrupt source
872   *            @arg HRTIM_TIM_IT_CPT2: Timer capture 2 Interrupt source
873   *            @arg HRTIM_TIM_IT_SET1: Timer output 1 set Interrupt source
874   *            @arg HRTIM_TIM_IT_RST1: Timer output 1 reset Interrupt source
875   *            @arg HRTIM_TIM_IT_SET2: Timer output 2 set Interrupt source
876   *            @arg HRTIM_TIM_IT_RST2: Timer output 2 reset Interrupt source
877   *            @arg HRTIM_TIM_IT_RST: Timer reset Interrupt source
878   *            @arg HRTIM_TIM_IT_DLYPRT1: Timer delay protection Interrupt source
879   * @param  NewState: new state of the TIM interrupts.
880   *          This parameter can be: ENABLE or DISABLE.
881   * @retval None
882   */
883 void HRTIM_ITConfig(HRTIM_TypeDef * HRTIMx, uint32_t TimerIdx, uint32_t HRTIM_IT, FunctionalState NewState)
884 {
885   if(TimerIdx != HRTIM_TIMERINDEX_MASTER)
886   {  
887     if(NewState != DISABLE)
888     {
889       HRTIMx->HRTIM_TIMERx[TimerIdx].TIMxDIER |= HRTIM_IT;
890     }
891     else
892     {
893       HRTIMx->HRTIM_TIMERx[TimerIdx].TIMxDIER &= ~HRTIM_IT;
894     }
895   }
896   else  
897   {
898     if(NewState != DISABLE)
899     {
900       HRTIMx->HRTIM_MASTER.MDIER |= HRTIM_IT;
901     }
902     else
903     {
904       HRTIMx->HRTIM_MASTER.MDIER &= ~HRTIM_IT;
905     }  
906   }
907 }
908
909 /**
910   * @brief  Enables or disables the common interrupt request
911   * @param  HRTIMx: pointer to HRTIMx peripheral
912   * @param  HRTIM_IT: specifies the HRTIM interrupts sources to be enabled or disabled.
913   *          This parameter can be any combination of the following values:
914   *            @arg HRTIM_IT_FLT1: Fault 1 interrupt source
915   *            @arg HRTIM_IT_FLT2: Fault 2 interrupt source
916   *            @arg HRTIM_IT_FLT3: Fault 3 interrupt Interrupt source
917   *            @arg HRTIM_IT_FLT4: Fault 4 Interrupt source
918   *            @arg HRTIM_IT_FLT5: Fault 5  Interrupt source
919   *            @arg HRTIM_IT_SYSFLT: System Fault Interrupt source
920   *            @arg HRTIM_IT_DLLRDY: DLL ready Interrupt source
921   *            @arg HRTIM_IT_BMPER: Burst mode period Interrupt source
922   * @param  NewState: new state of the TIM interrupts.
923   *          This parameter can be: ENABLE or DISABLE.
924   * @retval None
925   */
926 void HRTIM_ITCommonConfig(HRTIM_TypeDef * HRTIMx, uint32_t HRTIM_CommonIT, FunctionalState NewState)
927 {
928    if(NewState != DISABLE)
929     {
930       HRTIMx->HRTIM_COMMON.IER |= HRTIM_CommonIT;
931     }
932     else
933     {
934       HRTIMx->HRTIM_COMMON.IER &= ~HRTIM_CommonIT;
935     }
936 }
937
938 /**
939   * @brief  Clears the Master and slaves interrupt flags
940   * @param  HRTIMx: pointer to HRTIMx peripheral
941   * @param  TimerIdx: Timer index
942   *                   This parameter can be one of the following values:
943   *                   @arg 0x0 to 0x4 for timers A to E 
944   * @param  HRTIM_FLAG: specifies the HRTIM flags sources to be cleared.
945   *          This parameter can be any combination of the following values:
946   *            @arg HRTIM_MASTER_FLAG_MCMP1: Master compare 1 interrupt flag
947   *            @arg HRTIM_MASTER_FLAG_MCMP2: Master compare 2 interrupt flag
948   *            @arg HRTIM_MASTER_FLAG_MCMP3: Master compare 3 interrupt Interrupt flag
949   *            @arg HRTIM_MASTER_FLAG_MCMP4: Master compare 4 Interrupt flag
950   *            @arg HRTIM_MASTER_FLAG_MREP: Master Repetition Interrupt flag
951   *            @arg HRTIM_MASTER_FLAG_SYNC: Synchronization input Interrupt flag
952   *            @arg HRTIM_MASTER_FLAG_MUPD: Master update Interrupt flag
953   *            @arg HRTIM_TIM_FLAG_CMP1: Timer compare 1 Interrupt flag
954   *            @arg HRTIM_TIM_FLAG_CMP2: Timer compare 2 Interrupt flag
955   *            @arg HRTIM_TIM_FLAG_CMP3: Timer compare 3 Interrupt flag
956   *            @arg HRTIM_TIM_FLAG_CMP4: Timer compare 4 Interrupt flag
957   *            @arg HRTIM_TIM_FLAG_REP: Timer repetition Interrupt flag
958   *            @arg HRTIM_TIM_FLAG_UPD: Timer update Interrupt flag
959   *            @arg HRTIM_TIM_FLAG_CPT1: Timer capture 1 Interrupt flag
960   *            @arg HRTIM_TIM_FLAG_CPT2: Timer capture 2 Interrupt flag
961   *            @arg HRTIM_TIM_FLAG_SET1: Timer output 1 set Interrupt flag
962   *            @arg HRTIM_TIM_FLAG_RST1: Timer output 1 reset Interrupt flag
963   *            @arg HRTIM_TIM_FLAG_SET2: Timer output 2 set Interrupt flag
964   *            @arg HRTIM_TIM_FLAG_RST2: Timer output 2 reset Interrupt flag
965   *            @arg HRTIM_TIM_FLAG_RST: Timer reset Interrupt flag
966   *            @arg HRTIM_TIM_FLAG_DLYPRT1: Timer delay protection Interrupt flag
967   * @retval None
968   */
969 void HRTIM_ClearFlag(HRTIM_TypeDef * HRTIMx, uint32_t TimerIdx, uint32_t HRTIM_FLAG)
970 {
971   if(TimerIdx != HRTIM_TIMERINDEX_MASTER)
972   {
973     HRTIMx->HRTIM_MASTER.MICR |= HRTIM_FLAG;
974   }
975   else
976   {
977      HRTIMx->HRTIM_TIMERx[TimerIdx].TIMxICR |= HRTIM_FLAG;
978   }  
979 }
980
981 /**
982   * @brief  Clears the common interrupt flags
983   * @param  HRTIMx: pointer to HRTIMx peripheral
984   * @param  HRTIM_FLAG: specifies the HRTIM flags to be cleared.
985   *          This parameter can be any combination of the following values:
986   *            @arg HRTIM_FLAG_FLT1: Fault 1 interrupt flag
987   *            @arg HRTIM_FLAG_FLT2: Fault 2 interrupt flag
988   *            @arg HRTIM_FLAG_FLT3: Fault 3 interrupt Interrupt flag
989   *            @arg HRTIM_FLAG_FLT4: Fault 4 Interrupt flag
990   *            @arg HRTIM_FLAG_FLT5: Fault 5  Interrupt flag
991   *            @arg HRTIM_FLAG_SYSFLT: System Fault Interrupt flag
992   *            @arg HRTIM_FLAG_DLLRDY: DLL ready Interrupt flag
993   *            @arg HRTIM_FLAG_BMPER: Burst mode period Interrupt flag
994   * @retval None
995   */
996 void HRTIM_ClearCommonFlag(HRTIM_TypeDef * HRTIMx, uint32_t HRTIM_CommonFLAG)
997 {
998   HRTIMx->HRTIM_COMMON.ICR |= HRTIM_CommonFLAG;
999 }
1000
1001 /**
1002   * @brief  Clears the Master and slaves interrupt request pending bits
1003   * @param  HRTIMx: pointer to HRTIMx peripheral
1004   * @param  TimerIdx: Timer index
1005   *                   This parameter can be one of the following values:
1006   *                   @arg 0x0 to 0x4 for timers A to E 
1007   * @param  HRTIM_IT: specifies the HRTIM interrupts sources to be enabled or disabled.
1008   *          This parameter can be any combination of the following values:
1009   *            @arg HRTIM_MASTER_IT_MCMP1: Master compare 1 interrupt source
1010   *            @arg HRTIM_MASTER_IT_MCMP2: Master compare 2 interrupt source
1011   *            @arg HRTIM_MASTER_IT_MCMP3: Master compare 3 interrupt Interrupt source
1012   *            @arg HRTIM_MASTER_IT_MCMP4: Master compare 4 Interrupt source
1013   *            @arg HRTIM_MASTER_IT_MREP: Master Repetition Interrupt source
1014   *            @arg HRTIM_MASTER_IT_SYNC: Synchronization input Interrupt source
1015   *            @arg HRTIM_MASTER_IT_MUPD: Master update Interrupt source
1016   *            @arg HRTIM_TIM_IT_CMP1: Timer compare 1 Interrupt source
1017   *            @arg HRTIM_TIM_IT_CMP2: Timer compare 2 Interrupt source
1018   *            @arg HRTIM_TIM_IT_CMP3: Timer compare 3 Interrupt source
1019   *            @arg HRTIM_TIM_IT_CMP4: Timer compare 4 Interrupt source
1020   *            @arg HRTIM_TIM_IT_REP: Timer repetition Interrupt source
1021   *            @arg HRTIM_TIM_IT_UPD: Timer update Interrupt source
1022   *            @arg HRTIM_TIM_IT_CPT1: Timer capture 1 Interrupt source
1023   *            @arg HRTIM_TIM_IT_CPT2: Timer capture 2 Interrupt source
1024   *            @arg HRTIM_TIM_IT_SET1: Timer output 1 set Interrupt source
1025   *            @arg HRTIM_TIM_IT_RST1: Timer output 1 reset Interrupt source
1026   *            @arg HRTIM_TIM_IT_SET2: Timer output 2 set Interrupt source
1027   *            @arg HRTIM_TIM_IT_RST2: Timer output 2 reset Interrupt source
1028   *            @arg HRTIM_TIM_IT_RST: Timer reset Interrupt source
1029   *            @arg HRTIM_TIM_IT_DLYPRT: Timer delay protection Interrupt source
1030   * @retval None
1031   */
1032 void HRTIM_ClearITPendingBit(HRTIM_TypeDef * HRTIMx, uint32_t TimerIdx, uint32_t HRTIM_IT)
1033 {
1034   if(TimerIdx != HRTIM_TIMERINDEX_MASTER)
1035   {
1036     HRTIMx->HRTIM_TIMERx[TimerIdx].TIMxICR |= HRTIM_IT;
1037   }
1038   else 
1039   {   
1040     HRTIMx->HRTIM_MASTER.MICR |= HRTIM_IT;
1041   }
1042 }
1043
1044 /**
1045   * @brief  Clears the common interrupt pending bits
1046   * @param  HRTIMx: pointer to HRTIMx peripheral
1047   * @param  HRTIM_IT: specifies the HRTIM interrupts sources to be cleared.
1048   *          This parameter can be any combination of the following values:
1049   *            @arg HRTIM_IT_FLT1: Fault 1 interrupt source
1050   *            @arg HRTIM_IT_FLT2: Fault 2 interrupt source
1051   *            @arg HRTIM_IT_FLT3: Fault 3 interrupt Interrupt source
1052   *            @arg HRTIM_IT_FLT4: Fault 4 Interrupt source
1053   *            @arg HRTIM_IT_FLT5: Fault 5  Interrupt source
1054   *            @arg HRTIM_IT_SYSFLT: System Fault Interrupt source
1055   *            @arg HRTIM_IT_DLLRDY: DLL ready Interrupt source
1056   *            @arg HRTIM_IT_BMPER: Burst mode period Interrupt source
1057   * @retval None
1058   */
1059 void HRTIM_ClearCommonITPendingBit(HRTIM_TypeDef * HRTIMx, uint32_t HRTIM_CommonIT)
1060 {
1061   HRTIMx->HRTIM_COMMON.ICR |= HRTIM_CommonIT;
1062 }
1063
1064
1065 /**
1066   * @brief  Checks whether the specified HRTIM flag is set or not.
1067   * @param  HRTIMx: pointer to HRTIMx peripheral
1068   * @param  TimerIdx: Timer index
1069   *                   This parameter can be one of the following values:
1070   *                   @arg 0x0 to 0x4 for timers A to E 
1071   * @param  HRTIM_FLAG: specifies the HRTIM flags to check.
1072   *          This parameter can be any combination of the following values:
1073   *            @arg HRTIM_MASTER_FLAG_MCMP1: Master compare 1 interrupt flag
1074   *            @arg HRTIM_MASTER_FLAG_MCMP2: Master compare 2 interrupt flag
1075   *            @arg HRTIM_MASTER_FLAG_MCMP3: Master compare 3 interrupt Interrupt flag
1076   *            @arg HRTIM_MASTER_FLAG_MCMP4: Master compare 4 Interrupt flag
1077   *            @arg HRTIM_MASTER_FLAG_MREP: Master Repetition Interrupt flag
1078   *            @arg HRTIM_MASTER_FLAG_SYNC: Synchronization input Interrupt flag
1079   *            @arg HRTIM_MASTER_FLAG_MUPD: Master update Interrupt flag
1080   *            @arg HRTIM_TIM_FLAG_CMP1: Timer compare 1 Interrupt flag
1081   *            @arg HRTIM_TIM_FLAG_CMP2: Timer compare 2 Interrupt flag
1082   *            @arg HRTIM_TIM_FLAG_CMP3: Timer compare 3 Interrupt flag
1083   *            @arg HRTIM_TIM_FLAG_CMP4: Timer compare 4 Interrupt flag
1084   *            @arg HRTIM_TIM_FLAG_REP: Timer repetition Interrupt flag
1085   *            @arg HRTIM_TIM_FLAG_UPD: Timer update Interrupt flag
1086   *            @arg HRTIM_TIM_FLAG_CPT1: Timer capture 1 Interrupt flag
1087   *            @arg HRTIM_TIM_FLAG_CPT2: Timer capture 2 Interrupt flag
1088   *            @arg HRTIM_TIM_FLAG_SET1: Timer output 1 set Interrupt flag
1089   *            @arg HRTIM_TIM_FLAG_RST1: Timer output 1 reset Interrupt flag
1090   *            @arg HRTIM_TIM_FLAG_SET2: Timer output 2 set Interrupt flag
1091   *            @arg HRTIM_TIM_FLAG_RST2: Timer output 2 reset Interrupt flag
1092   *            @arg HRTIM_TIM_FLAG_RST: Timer reset Interrupt flag
1093   *            @arg HRTIM_TIM_FLAG_DLYPRT: Timer delay protection Interrupt flag
1094   * @retval The new state of HRTIM_FLAG (SET or RESET).
1095   */
1096 FlagStatus HRTIM_GetFlagStatus(HRTIM_TypeDef * HRTIMx, uint32_t TimerIdx, uint32_t HRTIM_FLAG)
1097 {
1098   FlagStatus bitstatus = RESET;  
1099
1100   if(TimerIdx != HRTIM_TIMERINDEX_MASTER)
1101   {  
1102     if ((HRTIMx->HRTIM_TIMERx[TimerIdx].TIMxISR & HRTIM_FLAG) != RESET)
1103     {
1104       bitstatus = SET;
1105     }
1106     else
1107     {
1108       bitstatus = RESET;
1109     }
1110   }
1111   else
1112   {
1113     if ((HRTIMx->HRTIM_MASTER.MISR & HRTIM_FLAG) != RESET)
1114     {
1115       bitstatus = SET;
1116     }
1117     else
1118     {
1119       bitstatus = RESET;
1120     }
1121   }  
1122   return bitstatus;
1123 }
1124
1125 /**
1126   * @brief  Checks whether the specified HRTIM common flag is set or not.
1127   * @param  HRTIMx: pointer to HRTIMx peripheral
1128   * @param  HRTIM_FLAG: specifies the HRTIM flags to check.
1129   *          This parameter can be any combination of the following values:
1130   *            @arg HRTIM_FLAG_FLT1: Fault 1 interrupt flag
1131   *            @arg HRTIM_FLAG_FLT2: Fault 2 interrupt flag
1132   *            @arg HRTIM_FLAG_FLT3: Fault 3 interrupt Interrupt flag
1133   *            @arg HRTIM_FLAG_FLT4: Fault 4 Interrupt flag
1134   *            @arg HRTIM_FLAG_FLT5: Fault 5  Interrupt flag
1135   *            @arg HRTIM_FLAG_SYSFLT: System Fault Interrupt flag
1136   *            @arg HRTIM_FLAG_DLLRDY: DLL ready Interrupt flag
1137   *            @arg HRTIM_FLAG_BMPER: Burst mode period Interrupt flag
1138   * @retval The new state of HRTIM_FLAG (SET or RESET).
1139   */
1140 FlagStatus HRTIM_GetCommonFlagStatus(HRTIM_TypeDef * HRTIMx, uint32_t HRTIM_CommonFLAG)
1141 {
1142   FlagStatus bitstatus = RESET;  
1143
1144   if((HRTIMx->HRTIM_COMMON.ISR & HRTIM_CommonFLAG) != RESET)
1145     {
1146       bitstatus = SET;
1147     }
1148     else
1149     {
1150       bitstatus = RESET;
1151     }
1152   return bitstatus;
1153 }
1154                                        
1155 /**
1156   * @brief  Checks whether the specified HRTIM interrupt has occurred or not.
1157   * @param  HRTIMx: pointer to HRTIMx peripheral
1158   * @param  TimerIdx: Timer index
1159   *                   This parameter can be one of the following values:
1160   *                   @arg 0x0 to 0x4 for timers A to E 
1161   * @param  HRTIM_IT: specifies the HRTIM flags sources to be cleared.
1162   *          This parameter can be any combination of the following values:
1163   *            @arg HRTIM_MASTER_IT_MCMP1: Master compare 1 interrupt 
1164   *            @arg HRTIM_MASTER_IT_MCMP2: Master compare 2 interrupt 
1165   *            @arg HRTIM_MASTER_IT_MCMP3: Master compare 3 interrupt Interrupt 
1166   *            @arg HRTIM_MASTER_IT_MCMP4: Master compare 4 Interrupt 
1167   *            @arg HRTIM_MASTER_IT_MREP: Master Repetition Interrupt 
1168   *            @arg HRTIM_MASTER_IT_SYNC: Synchronization input Interrupt 
1169   *            @arg HRTIM_MASTER_IT_MUPD: Master update Interrupt 
1170   *            @arg HRTIM_TIM_IT_CMP1: Timer compare 1 Interrupt 
1171   *            @arg HRTIM_TIM_IT_CMP2: Timer compare 2 Interrupt 
1172   *            @arg HRTIM_TIM_IT_CMP3: Timer compare 3 Interrupt 
1173   *            @arg HRTIM_TIM_IT_CMP4: Timer compare 4 Interrupt 
1174   *            @arg HRTIM_TIM_IT_REP: Timer repetition Interrupt 
1175   *            @arg HRTIM_TIM_IT_UPD: Timer update Interrupt 
1176   *            @arg HRTIM_TIM_IT_CPT1: Timer capture 1 Interrupt 
1177   *            @arg HRTIM_TIM_IT_CPT2: Timer capture 2 Interrupt 
1178   *            @arg HRTIM_TIM_IT_SET1: Timer output 1 set Interrupt 
1179   *            @arg HRTIM_TIM_IT_RST1: Timer output 1 reset Interrupt 
1180   *            @arg HRTIM_TIM_IT_SET2: Timer output 2 set Interrupt 
1181   *            @arg HRTIM_TIM_IT_RST2: Timer output 2 reset Interrupt 
1182   *            @arg HRTIM_TIM_IT_RST: Timer reset Interrupt 
1183   *            @arg HRTIM_TIM_IT_DLYPRT: Timer delay protection Interrupt 
1184   * @retval The new state of the HRTIM_IT(SET or RESET).
1185   */
1186 ITStatus HRTIM_GetITStatus(HRTIM_TypeDef * HRTIMx, uint32_t TimerIdx, uint32_t HRTIM_IT)
1187 {
1188   ITStatus bitstatus = RESET;  
1189   uint16_t itstatus = 0x0, itenable = 0x0;
1190
1191   if(TimerIdx != HRTIM_TIMERINDEX_MASTER)
1192   {  
1193     itstatus = HRTIMx->HRTIM_TIMERx[TimerIdx].TIMxISR & HRTIM_IT;
1194   
1195     itenable = HRTIMx->HRTIM_TIMERx[TimerIdx].TIMxDIER & HRTIM_IT;
1196     if ((itstatus != (uint16_t)RESET) && (itenable != (uint16_t)RESET))
1197     {
1198       bitstatus = SET;
1199     }
1200     else
1201     {
1202       bitstatus = RESET;
1203     }
1204   }
1205   else
1206   {
1207     itstatus = HRTIMx->HRTIM_MASTER.MISR & HRTIM_IT;
1208   
1209     itenable = HRTIMx->HRTIM_MASTER.MDIER & HRTIM_IT;
1210     if ((itstatus != (uint16_t)RESET) && (itenable != (uint16_t)RESET))
1211     {
1212       bitstatus = SET;
1213     }
1214     else
1215     {
1216       bitstatus = RESET;
1217     }
1218   }  
1219   return bitstatus;
1220 }
1221
1222 /**
1223   * @brief  Checks whether the specified HRTIM common interrupt has occurred or not.
1224   * @param  HRTIMx: pointer to HRTIMx peripheral
1225   * @param  HRTIM_IT: specifies the HRTIM interrupt source to check.
1226   *          This parameter can be any combination of the following values:
1227   *            @arg HRTIM_IT_FLT1: Fault 1 interrupt 
1228   *            @arg HRTIM_IT_FLT2: Fault 2 interrupt 
1229   *            @arg HRTIM_IT_FLT3: Fault 3 interrupt Interrupt 
1230   *            @arg HRTIM_IT_FLT4: Fault 4 Interrupt 
1231   *            @arg HRTIM_IT_FLT5: Fault 5  Interrupt 
1232   *            @arg HRTIM_IT_SYSFLT: System Fault Interrupt 
1233   *            @arg HRTIM_IT_DLLRDY: DLL ready Interrupt flag
1234   *            @arg HRTIM_IT_BMPER: Burst mode period Interrupt 
1235   * @retval The new state of HRTIM_FLAG (SET or RESET).
1236   */
1237 ITStatus HRTIM_GetCommonITStatus(HRTIM_TypeDef * HRTIMx, uint32_t HRTIM_CommonIT)
1238 {
1239   ITStatus bitstatus = RESET;  
1240   uint16_t itstatus = 0x0, itenable = 0x0;
1241  
1242   itstatus = HRTIMx->HRTIM_COMMON.ISR & HRTIM_CommonIT; 
1243   itenable = HRTIMx->HRTIM_COMMON.IER & HRTIM_CommonIT;
1244   
1245   if ((itstatus != (uint16_t)RESET) && (itenable != (uint16_t)RESET))
1246   {
1247     bitstatus = SET;
1248   }
1249   else
1250   {
1251     bitstatus = RESET;
1252   }
1253
1254   return bitstatus;
1255 }
1256
1257 /**
1258   * @brief  Enables or disables the HRTIMx's DMA Requests.
1259   * @param  HRTIMx: pointer to HRTIMx peripheral
1260   * @param  TimerIdx: Timer index
1261   *                   This parameter can be one of the following values:
1262   *                   @arg 0x0 to 0x4 for timers A to E 
1263   * @param  HRTIM_DMA: specifies the DMA Request sources.
1264   *          This parameter can be any combination of the following values:
1265   *            @arg HRTIM_MASTER_DMA_MCMP1: Master compare 1 DMA request source
1266   *            @arg HRTIM_MASTER_DMA_MCMP2: Master compare 2 DMA request source
1267   *            @arg HRTIM_MASTER_DMA_MCMP3: Master compare 3 DMA request source
1268   *            @arg HRTIM_MASTER_DMA_MCMP4: Master compare 4 DMA request source
1269   *            @arg HRTIM_MASTER_DMA_MREP: Master Repetition DMA request source
1270   *            @arg HRTIM_MASTER_DMA_SYNC: Synchronization input DMA request source
1271   *            @arg HRTIM_MASTER_DMA_MUPD:Master update DMA request source
1272   *            @arg HRTIM_TIM_DMA_CMP1: Timer compare 1 DMA request source 
1273   *            @arg HRTIM_TIM_DMA_CMP2: Timer compare 2 DMA request source 
1274   *            @arg HRTIM_TIM_DMA_CMP3: Timer compare 3 DMA request source 
1275   *            @arg HRTIM_TIM_DMA_CMP4: Timer compare 4 DMA request source 
1276   *            @arg HRTIM_TIM_DMA_REP: Timer repetition DMA request source 
1277   *            @arg HRTIM_TIM_DMA_UPD: Timer update DMA request source 
1278   *            @arg HRTIM_TIM_DMA_CPT1: Timer capture 1 DMA request source 
1279   *            @arg HRTIM_TIM_DMA_CPT2: Timer capture 2 DMA request source 
1280   *            @arg HRTIM_TIM_DMA_SET1: Timer output 1 set DMA request source 
1281   *            @arg HRTIM_TIM_DMA_RST1: Timer output 1 reset DMA request source 
1282   *            @arg HRTIM_TIM_DMA_SET2: Timer output 2 set DMA request source 
1283   *            @arg HRTIM_TIM_DMA_RST2: Timer output 2 reset DMA request source 
1284   *            @arg HRTIM_TIM_DMA_RST: Timer reset DMA request source 
1285   *            @arg HRTIM_TIM_DMA_DLYPRT: Timer delay protection DMA request source 
1286   * @param  NewState: new state of the DMA Request sources.
1287   *          This parameter can be: ENABLE or DISABLE.
1288   * @retval None
1289   */
1290 void HRTIM_DMACmd(HRTIM_TypeDef* HRTIMx, uint32_t TimerIdx, uint32_t HRTIM_DMA, FunctionalState NewState)
1291 {
1292   if(TimerIdx != HRTIM_TIMERINDEX_MASTER)
1293   { 
1294      if(NewState != DISABLE)
1295      {
1296        HRTIMx->HRTIM_TIMERx[TimerIdx].TIMxDIER |= HRTIM_DMA;
1297      }
1298      else
1299      {
1300        HRTIMx->HRTIM_TIMERx[TimerIdx].TIMxDIER &= ~HRTIM_DMA;
1301      }
1302   }
1303   else
1304   {
1305      if(NewState != DISABLE)
1306      {
1307        HRTIMx->HRTIM_MASTER.MDIER |= HRTIM_DMA;
1308      }
1309      else
1310      {
1311        HRTIMx->HRTIM_MASTER.MDIER &= ~HRTIM_DMA;
1312      }
1313   }  
1314 }
1315
1316 /**
1317   * @}
1318   */
1319
1320 /** @defgroup HRTIM_Group3 Peripheral Control methods 
1321  *  @brief   management functions 
1322  *
1323 @verbatim   
1324  ===============================================================================
1325                       ##### Peripheral Control methods #####
1326  ===============================================================================  
1327     [..]
1328     This subsection provides a set of functions allowing to control the HRTIMx data 
1329     transfers.
1330
1331 @endverbatim
1332   * @{
1333   */
1334
1335 /**
1336   * @brief  Configures an output in basic output compare mode 
1337   * @param  HRTIMx: pointer to HRTIMx peripheral
1338   * @param  TimerIdx: Timer index
1339   *                   This parameter can be one of the following values:
1340   *                   @arg 0x0 to 0x4 for timers A to E 
1341   * @param  OCChannel: Timer output
1342   *                    This parameter can be one of the following values:
1343   *                    @arg HRTIM_OUTPUT_TA1: Timer A - Output 1
1344   *                    @arg HRTIM_OUTPUT_TA2: Timer A - Output 2
1345   *                    @arg HRTIM_OUTPUT_TB1: Timer B - Output 1
1346   *                    @arg HRTIM_OUTPUT_TB2: Timer B - Output 2
1347   *                    @arg HRTIM_OUTPUT_TC1: Timer C - Output 1
1348   *                    @arg HRTIM_OUTPUT_TC2: Timer C - Output 2
1349   *                    @arg HRTIM_OUTPUT_TD1: Timer D - Output 1
1350   *                    @arg HRTIM_OUTPUT_TD2: Timer D - Output 2
1351   *                    @arg HRTIM_OUTPUT_TE1: Timer E - Output 1
1352   *                    @arg HRTIM_OUTPUT_TE2: Timer E - Output 2 
1353   * @param  pBasicOCChannelCfg: pointer to the basic output compare output configuration structure
1354   * @note When the timer operates in basic output compare mode:
1355   *         Output 1 is implicitely controled by the compare unit 1
1356   *         Output 2 is implicitely controled by the compare unit 2
1357   *       Output Set/Reset crossbar is set according to the selected output compare mode:
1358   *         Toggle: SETxyR = RSTxyR = CMPy
1359   *         Active: SETxyR = CMPy, RSTxyR = 0
1360   *         Inactive: SETxy =0, RSTxy = CMPy
1361   * @retval None
1362   */
1363 void HRTIM_SimpleOCChannelConfig(HRTIM_TypeDef * HRTIM_,
1364                                                  uint32_t TimerIdx,
1365                                                  uint32_t OCChannel,
1366                                                  HRTIM_BasicOCChannelCfgTypeDef* pBasicOCChannelCfg)
1367 {
1368   uint32_t CompareUnit = HRTIM_COMPAREUNIT_1;
1369   HRTIM_CompareCfgTypeDef CompareCfg;
1370   HRTIM_OutputCfgTypeDef OutputCfg;
1371   
1372   /* Check parameters */
1373   assert_param(IS_HRTIM_TIMER_OUTPUT(TimerIdx, OCChannel));
1374   assert_param(IS_HRTIM_BASICOCMODE(pBasicOCChannelCfg->Mode));
1375   assert_param(IS_HRTIM_OUTPUTPOLARITY(pBasicOCChannelCfg->Polarity));
1376   assert_param(IS_HRTIM_OUTPUTIDLESTATE(pBasicOCChannelCfg->IdleState));
1377     
1378   /* Configure timer compare unit */  
1379   switch (OCChannel)
1380   {
1381     case HRTIM_OUTPUT_TA1:
1382     case HRTIM_OUTPUT_TB1:
1383     case HRTIM_OUTPUT_TC1:
1384     case HRTIM_OUTPUT_TD1:
1385     case HRTIM_OUTPUT_TE1:
1386     {
1387       CompareUnit = HRTIM_COMPAREUNIT_1;
1388     }
1389     break;
1390     case HRTIM_OUTPUT_TA2:
1391     case HRTIM_OUTPUT_TB2:
1392     case HRTIM_OUTPUT_TC2:
1393     case HRTIM_OUTPUT_TD2:
1394     case HRTIM_OUTPUT_TE2:
1395     {
1396       CompareUnit = HRTIM_COMPAREUNIT_2;
1397     }
1398     break;
1399     default:
1400     break;
1401   }
1402   
1403   CompareCfg.CompareValue = pBasicOCChannelCfg->Pulse;
1404   CompareCfg.AutoDelayedMode = HRTIM_AUTODELAYEDMODE_REGULAR;
1405   CompareCfg.AutoDelayedTimeout = 0;
1406   
1407   HRTIM_CompareUnitConfig(HRTIM_,
1408                           TimerIdx,
1409                           CompareUnit,
1410                           &CompareCfg);
1411   
1412   /* Configure timer output */
1413   OutputCfg.Polarity = pBasicOCChannelCfg->Polarity;
1414   OutputCfg.IdleState = pBasicOCChannelCfg->IdleState;
1415   OutputCfg.FaultState = HRTIM_OUTPUTFAULTSTATE_NONE;
1416   OutputCfg.IdleMode = HRTIM_OUTPUTIDLEMODE_NONE;
1417   OutputCfg.ChopperModeEnable = HRTIM_OUTPUTCHOPPERMODE_DISABLED;
1418   OutputCfg.BurstModeEntryDelayed = HRTIM_OUTPUTBURSTMODEENTRY_REGULAR;
1419   
1420   switch (pBasicOCChannelCfg->Mode)
1421   {
1422     case HRTIM_BASICOCMODE_TOGGLE:
1423     {
1424       if (CompareUnit == HRTIM_COMPAREUNIT_1)
1425       {
1426         OutputCfg.SetSource = HRTIM_OUTPUTSET_TIMCMP1;
1427       }
1428       else
1429       {
1430         OutputCfg.SetSource = HRTIM_OUTPUTSET_TIMCMP2;
1431       }
1432       OutputCfg.ResetSource = OutputCfg.SetSource;
1433     }
1434     break;
1435     case HRTIM_BASICOCMODE_ACTIVE:
1436     {
1437       if (CompareUnit == HRTIM_COMPAREUNIT_1)
1438       {
1439         OutputCfg.SetSource = HRTIM_OUTPUTSET_TIMCMP1;
1440       }
1441       else
1442       {
1443         OutputCfg.SetSource = HRTIM_OUTPUTSET_TIMCMP2;
1444       }
1445       OutputCfg.ResetSource = HRTIM_OUTPUTRESET_NONE;
1446     }
1447     break;
1448     case HRTIM_BASICOCMODE_INACTIVE:
1449     {
1450       if (CompareUnit == HRTIM_COMPAREUNIT_1)
1451       {
1452         OutputCfg.ResetSource = HRTIM_OUTPUTRESET_TIMCMP1;
1453       }
1454       else
1455       {
1456         OutputCfg.ResetSource = HRTIM_OUTPUTRESET_TIMCMP2;
1457       }
1458       OutputCfg.SetSource = HRTIM_OUTPUTSET_NONE;
1459     }
1460     break;
1461     default:
1462     break;  
1463   }
1464   
1465   HRTIM_OutputConfig(HRTIM_, TimerIdx, OCChannel, &OutputCfg);   
1466 }
1467
1468 /**
1469   * @brief  Configures an output in basic PWM mode 
1470   * @param  HRTIMx: pointer to HRTIMx peripheral
1471   * @param  TimerIdx: Timer index
1472   *                   This parameter can be one of the following values:
1473   *                   @arg 0x0 to 0x4 for timers A to E 
1474   * @param  PWMChannel: Timer output
1475   *                    This parameter can be one of the following values:
1476   *                    @arg HRTIM_OUTPUT_TA1: Timer A - Output 1
1477   *                    @arg HRTIM_OUTPUT_TA2: Timer A - Output 2
1478   *                    @arg HRTIM_OUTPUT_TB1: Timer B - Output 1
1479   *                    @arg HRTIM_OUTPUT_TB2: Timer B - Output 2
1480   *                    @arg HRTIM_OUTPUT_TC1: Timer C - Output 1
1481   *                    @arg HRTIM_OUTPUT_TC2: Timer C - Output 2
1482   *                    @arg HRTIM_OUTPUT_TD1: Timer D - Output 1
1483   *                    @arg HRTIM_OUTPUT_TD2: Timer D - Output 2
1484   *                    @arg HRTIM_OUTPUT_TE1: Timer E - Output 1
1485   *                    @arg HRTIM_OUTPUT_TE2: Timer E - Output 2 
1486   * @param  pBasicPWMChannelCfg: pointer to the basic PWM output configuration structure
1487   * @note When the timer operates in basic PWM output mode:
1488   *         Output 1 is implicitly controled by the compare unit 1
1489   *         Output 2 is implicitly controled by the compare unit 2
1490   *         Output Set/Reset crossbar is set as follows:
1491   *         Output 1: SETx1R = CMP1, RSTx1R = PER
1492   *         Output 2: SETx2R = CMP2, RST2R = PER
1493   * @retval None
1494   */
1495 void HRTIM_SimplePWMChannelConfig(HRTIM_TypeDef * HRTIM_,
1496                                                   uint32_t TimerIdx,
1497                                                   uint32_t PWMChannel,
1498                                                   HRTIM_BasicPWMChannelCfgTypeDef* pBasicPWMChannelCfg)
1499 {
1500   uint32_t CompareUnit = HRTIM_COMPAREUNIT_1;
1501   HRTIM_CompareCfgTypeDef CompareCfg;
1502   HRTIM_OutputCfgTypeDef OutputCfg;
1503
1504   /* Check parameters */
1505   assert_param(IS_HRTIM_TIMER_OUTPUT(TimerIdx, PWMChannel));
1506   assert_param(IS_HRTIM_OUTPUTPOLARITY(pBasicPWMChannelCfg->Polarity));
1507   assert_param(IS_HRTIM_OUTPUTIDLESTATE(pBasicPWMChannelCfg->IdleState));
1508
1509   /* Configure timer compare unit */  
1510   switch (PWMChannel)
1511   {
1512     case HRTIM_OUTPUT_TA1:
1513     case HRTIM_OUTPUT_TB1:
1514     case HRTIM_OUTPUT_TC1:
1515     case HRTIM_OUTPUT_TD1:
1516     case HRTIM_OUTPUT_TE1:
1517     {
1518       CompareUnit = HRTIM_COMPAREUNIT_1;
1519     }
1520     break;
1521     case HRTIM_OUTPUT_TA2:
1522     case HRTIM_OUTPUT_TB2:
1523     case HRTIM_OUTPUT_TC2:
1524     case HRTIM_OUTPUT_TD2:
1525     case HRTIM_OUTPUT_TE2:
1526     {
1527       CompareUnit = HRTIM_COMPAREUNIT_2;
1528     }
1529     break;
1530     default:
1531     break;  
1532   }
1533   
1534   CompareCfg.CompareValue = pBasicPWMChannelCfg->Pulse;
1535   CompareCfg.AutoDelayedMode = HRTIM_AUTODELAYEDMODE_REGULAR;
1536   CompareCfg.AutoDelayedTimeout = 0;
1537   
1538   HRTIM_CompareUnitConfig(HRTIM_,
1539                           TimerIdx,
1540                           CompareUnit,
1541                           &CompareCfg);
1542   
1543   /* Configure timer output */
1544   OutputCfg.Polarity = pBasicPWMChannelCfg->Polarity;
1545   OutputCfg.IdleState = pBasicPWMChannelCfg->IdleState;
1546   OutputCfg.FaultState = HRTIM_OUTPUTFAULTSTATE_NONE;
1547   OutputCfg.IdleMode = HRTIM_OUTPUTIDLEMODE_NONE;
1548   OutputCfg.ChopperModeEnable = HRTIM_OUTPUTCHOPPERMODE_DISABLED;
1549   OutputCfg.BurstModeEntryDelayed = HRTIM_OUTPUTBURSTMODEENTRY_REGULAR;
1550   
1551   if (CompareUnit == HRTIM_COMPAREUNIT_1)
1552   {
1553     OutputCfg.SetSource = HRTIM_OUTPUTSET_TIMCMP1;
1554   }
1555   else
1556   {
1557     OutputCfg.SetSource = HRTIM_OUTPUTSET_TIMCMP2;
1558   }
1559   OutputCfg.ResetSource = HRTIM_OUTPUTSET_TIMPER;
1560   
1561   HRTIM_OutputConfig(HRTIM_, TimerIdx, PWMChannel, &OutputCfg);  
1562 }
1563
1564 /**
1565   * @brief  Configures a basic capture 
1566   * @param  HRTIMx: pointer to HRTIMx peripheral
1567   * @param  TimerIdx: Timer index
1568   *                   This parameter can be one of the following values:
1569   *                   @arg 0x0 to 0x4 for timers A to E 
1570   * @param  CaptureChannel: Capture unit
1571   *                    This parameter can be one of the following values: 
1572   *                    @arg HRTIM_CAPTUREUNIT_1: Capture unit 1
1573   *                    @arg HRTIM_CAPTUREUNIT_2: Capture unit 2
1574   * @param  pBasicCaptureChannelCfg: pointer to the basic capture configuration structure
1575   * @note When the timer operates in basic capture mode the capture is triggered
1576   *       by the designated external event and GPIO input is implicitly used as event source.
1577   *       The cature can be triggered by a rising edge, a falling edge or both
1578   *       edges on event channel.
1579   * @retval None
1580   */
1581 void HRTIM_SimpleCaptureChannelConfig(HRTIM_TypeDef * HRTIMx,
1582                                                       uint32_t TimerIdx,
1583                                                       uint32_t CaptureChannel,
1584                                                       HRTIM_BasicCaptureChannelCfgTypeDef* pBasicCaptureChannelCfg)
1585 {
1586   HRTIM_EventCfgTypeDef EventCfg;
1587   
1588   /* Check parameters */
1589   assert_param(IS_HRTIM_TIMING_UNIT(TimerIdx));
1590   assert_param(IS_HRTIM_CAPTUREUNIT(CaptureChannel));
1591   assert_param(IS_HRTIM_EVENT(pBasicCaptureChannelCfg->Event));
1592   assert_param(IS_HRTIM_EVENTPOLARITY(pBasicCaptureChannelCfg->EventPolarity));
1593   assert_param(IS_HRTIM_EVENTSENSITIVITY(pBasicCaptureChannelCfg->EventSensitivity));
1594   assert_param(IS_HRTIM_EVENTFILTER(pBasicCaptureChannelCfg->EventFilter));
1595   
1596   /* Configure external event channel */
1597   EventCfg.FastMode = HRTIM_EVENTFASTMODE_DISABLE;
1598   EventCfg.Filter = pBasicCaptureChannelCfg->EventFilter;
1599   EventCfg.Polarity = pBasicCaptureChannelCfg->EventPolarity;
1600   EventCfg.Sensitivity = pBasicCaptureChannelCfg->EventSensitivity;
1601   EventCfg.Source = HRTIM_EVENTSRC_1;
1602     
1603   HRTIM_ExternalEventConfig(HRTIMx,
1604                     pBasicCaptureChannelCfg->Event,
1605                     &EventCfg);
1606
1607   /* Memorize capture trigger (will be configured when the capture is started */  
1608   HRTIM_CaptureUnitConfig(HRTIMx,
1609                           TimerIdx,
1610                           CaptureChannel,
1611                           pBasicCaptureChannelCfg->Event); 
1612 }
1613
1614 /**
1615   * @brief  Configures an output basic one pulse mode 
1616   * @param  HRTIMx: pointer to HRTIMx peripheral
1617   * @param  TimerIdx: Timer index
1618   *                   This parameter can be one of the following values:
1619   *                   @arg 0x0 to 0x4 for timers A to E 
1620   * @param  OnePulseChannel: Timer output
1621   *                    This parameter can be one of the following values:
1622   *                    @arg HRTIM_OUTPUT_TA1: Timer A - Output 1
1623   *                    @arg HRTIM_OUTPUT_TA2: Timer A - Output 2
1624   *                    @arg HRTIM_OUTPUT_TB1: Timer B - Output 1
1625   *                    @arg HRTIM_OUTPUT_TB2: Timer B - Output 2
1626   *                    @arg HRTIM_OUTPUT_TC1: Timer C - Output 1
1627   *                    @arg HRTIM_OUTPUT_TC2: Timer C - Output 2
1628   *                    @arg HRTIM_OUTPUT_TD1: Timer D - Output 1
1629   *                    @arg HRTIM_OUTPUT_TD2: Timer D - Output 2
1630   *                    @arg HRTIM_OUTPUT_TE1: Timer E - Output 1
1631   *                    @arg HRTIM_OUTPUT_TE2: Timer E - Output 2 
1632   * @param  pBasicOnePulseChannelCfg: pointer to the basic one pulse output configuration structure
1633   * @note When the timer operates in basic one pulse mode:
1634   *         the timer counter is implicitly started by the reset event,
1635   *         the reset of the timer counter is triggered by the designated external event
1636   *         GPIO input is implicitly used as event source,
1637   *         Output 1 is implicitly controled by the compare unit 1,
1638   *         Output 2 is implicitly controled by the compare unit 2.
1639   *         Output Set/Reset crossbar is set as follows:
1640   *         Output 1: SETx1R = CMP1, RSTx1R = PER
1641   *         Output 2: SETx2R = CMP2, RST2R = PER
1642   *         The counter mode should be HRTIM_MODE_SINGLESHOT_RETRIGGERABLE
1643   * @retval None
1644   */
1645 void HRTIM_SimpleOnePulseChannelConfig(HRTIM_TypeDef * HRTIM_,
1646                                                        uint32_t TimerIdx,
1647                                                        uint32_t OnePulseChannel,
1648                                                        HRTIM_BasicOnePulseChannelCfgTypeDef* pBasicOnePulseChannelCfg)
1649 {
1650   uint32_t CompareUnit = HRTIM_COMPAREUNIT_1;
1651   HRTIM_CompareCfgTypeDef CompareCfg;
1652   HRTIM_OutputCfgTypeDef OutputCfg;
1653   HRTIM_EventCfgTypeDef EventCfg;
1654   
1655   /* Check parameters */
1656   assert_param(IS_HRTIM_TIMER_OUTPUT(TimerIdx, OnePulseChannel));
1657   assert_param(IS_HRTIM_OUTPUTPOLARITY(pBasicOnePulseChannelCfg->OutputPolarity));
1658   assert_param(IS_HRTIM_OUTPUTIDLESTATE(pBasicOnePulseChannelCfg->OutputIdleState));
1659   assert_param(IS_HRTIM_EVENT(pBasicOnePulseChannelCfg->Event));
1660   assert_param(IS_HRTIM_EVENTPOLARITY(pBasicOnePulseChannelCfg->EventPolarity));
1661   assert_param(IS_HRTIM_EVENTSENSITIVITY(pBasicOnePulseChannelCfg->EventSensitivity));
1662   assert_param(IS_HRTIM_EVENTFILTER(pBasicOnePulseChannelCfg->EventFilter));
1663   
1664   /* Configure timer compare unit */  
1665   switch (OnePulseChannel)
1666   {
1667     case HRTIM_OUTPUT_TA1:
1668     case HRTIM_OUTPUT_TB1:
1669     case HRTIM_OUTPUT_TC1:
1670     case HRTIM_OUTPUT_TD1:
1671     case HRTIM_OUTPUT_TE1:
1672     {
1673       CompareUnit = HRTIM_COMPAREUNIT_1;
1674     }
1675     break;
1676     case HRTIM_OUTPUT_TA2:
1677     case HRTIM_OUTPUT_TB2:
1678     case HRTIM_OUTPUT_TC2:
1679     case HRTIM_OUTPUT_TD2:
1680     case HRTIM_OUTPUT_TE2:
1681     {
1682       CompareUnit = HRTIM_COMPAREUNIT_2;
1683     }
1684     break;
1685     default:
1686     break;      
1687   }
1688   
1689   CompareCfg.CompareValue = pBasicOnePulseChannelCfg->Pulse;
1690   CompareCfg.AutoDelayedMode = HRTIM_AUTODELAYEDMODE_REGULAR;
1691   CompareCfg.AutoDelayedTimeout = 0;
1692   
1693   HRTIM_CompareUnitConfig(HRTIM_,
1694                           TimerIdx,
1695                           CompareUnit,
1696                           &CompareCfg);
1697   
1698   /* Configure timer output */
1699   OutputCfg.Polarity = pBasicOnePulseChannelCfg->OutputPolarity;
1700   OutputCfg.IdleState = pBasicOnePulseChannelCfg->OutputIdleState;
1701   OutputCfg.FaultState = HRTIM_OUTPUTFAULTSTATE_NONE;
1702   OutputCfg.IdleMode = HRTIM_OUTPUTIDLEMODE_NONE;
1703   OutputCfg.ChopperModeEnable = HRTIM_OUTPUTCHOPPERMODE_DISABLED;
1704   OutputCfg.BurstModeEntryDelayed = HRTIM_OUTPUTBURSTMODEENTRY_REGULAR;
1705   
1706   if (CompareUnit == HRTIM_COMPAREUNIT_1)
1707   {
1708     OutputCfg.SetSource = HRTIM_OUTPUTSET_TIMCMP1;
1709   }
1710   else
1711   {
1712     OutputCfg.SetSource = HRTIM_OUTPUTSET_TIMCMP2;
1713   }
1714   OutputCfg.ResetSource = HRTIM_OUTPUTSET_TIMPER;
1715   
1716   HRTIM_OutputConfig(HRTIM_,
1717                      TimerIdx,
1718                      OnePulseChannel,
1719                      &OutputCfg);  
1720   
1721   /* Configure external event channel */
1722   EventCfg.FastMode = HRTIM_EVENTFASTMODE_DISABLE;
1723   EventCfg.Filter = pBasicOnePulseChannelCfg->EventFilter;
1724   EventCfg.Polarity = pBasicOnePulseChannelCfg->EventPolarity;
1725   EventCfg.Sensitivity = pBasicOnePulseChannelCfg->EventSensitivity;
1726   EventCfg.Source = HRTIM_EVENTSRC_1;
1727     
1728   HRTIM_ExternalEventConfig(HRTIM_,
1729                     pBasicOnePulseChannelCfg->Event,
1730                     &EventCfg);
1731
1732   /* Configure the timer reset register */
1733   HRTIM_TIM_ResetConfig(HRTIM_,
1734                         TimerIdx, 
1735                         pBasicOnePulseChannelCfg->Event);  
1736 }
1737
1738 /**
1739   * @brief  Configures the general behavior of a timer operating in waveform mode 
1740   * @param  HRTIMx: pointer to HRTIMx peripheral
1741   * @param  TimerIdx: Timer index
1742   *                   This parameter can be one of the following values:
1743   *                   @arg 0x0 to 0x4 for timers A to E 
1744   * @param  pTimerCfg: pointer to the timer configuration structure
1745   * @note When the timer operates in waveform mode, all the features supported by
1746   *       the HRTIMx are available without any limitation.
1747   * @retval None
1748   */
1749 void HRTIM_WaveformTimerConfig(HRTIM_TypeDef * HRTIMx,
1750                                                 uint32_t TimerIdx,
1751                                                 HRTIM_TimerCfgTypeDef * pTimerCfg)
1752 {
1753   uint32_t HRTIM_timcr;
1754   uint32_t HRTIM_timfltr;
1755   uint32_t HRTIM_timoutr;
1756   uint32_t HRTIM_timrstr;
1757
1758   /* Check parameters */
1759   assert_param(IS_HRTIM_TIMING_UNIT(TimerIdx));
1760   assert_param(IS_HRTIM_TIMPUSHPULLMODE(pTimerCfg->PushPull));
1761   assert_param(IS_HRTIM_TIMFAULTENABLE(pTimerCfg->FaultEnable));
1762   assert_param(IS_HRTIM_TIMFAULTLOCK(pTimerCfg->FaultLock));
1763   assert_param(IS_HRTIM_TIMDEADTIMEINSERTION(pTimerCfg->DeadTimeInsertion));
1764   assert_param(IS_HRTIM_TIMDELAYEDPROTECTION(pTimerCfg->DelayedProtectionMode));
1765   assert_param(IS_HRTIM_TIMUPDATETRIGGER(pTimerCfg->UpdateTrigger)); 
1766   assert_param(IS_HRTIM_TIMRESETTRIGGER(pTimerCfg->ResetTrigger));
1767   assert_param(IS_HRTIM_TIMUPDATEONRESET(pTimerCfg->ResetUpdate));
1768
1769   /* Configure timing unit (Timer A to Timer E) */
1770   HRTIM_timcr = HRTIMx->HRTIM_TIMERx[TimerIdx].TIMxCR;
1771   HRTIM_timfltr  = HRTIMx->HRTIM_TIMERx[TimerIdx].FLTxR;
1772   HRTIM_timoutr  = HRTIMx->HRTIM_TIMERx[TimerIdx].OUTxR;
1773   HRTIM_timrstr  = HRTIMx->HRTIM_TIMERx[TimerIdx].RSTxR;
1774   
1775   /* Set the push-pull mode */
1776   HRTIM_timcr &= ~(HRTIM_TIMCR_PSHPLL);
1777   HRTIM_timcr |= pTimerCfg->PushPull;
1778   
1779   /* Enable/Disable registers update on timer counter reset */
1780   HRTIM_timcr &= ~(HRTIM_TIMCR_TRSTU);
1781   HRTIM_timcr |= pTimerCfg->ResetUpdate;
1782   
1783   /* Set the timer update trigger */
1784   HRTIM_timcr &= ~(HRTIM_TIMCR_TIMUPDATETRIGGER);
1785   HRTIM_timcr |= pTimerCfg->UpdateTrigger;
1786   
1787   /* Enable/Disable the fault channel at timer level */
1788   HRTIM_timfltr &= ~(HRTIM_FLTR_FLTxEN);
1789   HRTIM_timfltr |= (pTimerCfg->FaultEnable & HRTIM_FLTR_FLTxEN);
1790   
1791   /* Lock/Unlock fault sources at timer level */
1792   HRTIM_timfltr &= ~(HRTIM_FLTR_FLTCLK);
1793   HRTIM_timfltr |= pTimerCfg->FaultLock;
1794   
1795   /* Enable/Disable dead time insertion at timer level */
1796   HRTIM_timoutr &= ~(HRTIM_OUTR_DTEN);
1797   HRTIM_timoutr |= pTimerCfg->DeadTimeInsertion;
1798
1799   /* Enable/Disable delayed protection at timer level */
1800   HRTIM_timoutr &= ~(HRTIM_OUTR_DLYPRT| HRTIM_OUTR_DLYPRTEN);
1801   HRTIM_timoutr |= pTimerCfg->DelayedProtectionMode;
1802   
1803   /* Set the timer counter reset trigger */
1804   HRTIM_timrstr = pTimerCfg->ResetTrigger;
1805
1806   /* Update the HRTIMx registers */
1807   HRTIMx->HRTIM_TIMERx[TimerIdx].TIMxCR  = HRTIM_timcr;
1808   HRTIMx->HRTIM_TIMERx[TimerIdx].FLTxR = HRTIM_timfltr;
1809   HRTIMx->HRTIM_TIMERx[TimerIdx].OUTxR = HRTIM_timoutr;
1810   HRTIMx->HRTIM_TIMERx[TimerIdx].RSTxR = HRTIM_timrstr;
1811  }
1812
1813 /**
1814   * @brief  Configures the compare unit of a timer operating in waveform mode 
1815   * @param  HRTIMx: pointer to HRTIMx peripheral
1816   * @param  TimerIdx: Timer index
1817   *                   0xFF for master timer
1818   *                   This parameter can be one of the following values:
1819   *                   @arg 0x0 to 0x4 for timers A to E 
1820   * @param  CompareUnit: Compare unit to configure
1821   *                    This parameter can be one of the following values: 
1822   *                    @arg HRTIM_COMPAREUNIT_1: Compare unit 1
1823   *                    @arg HRTIM_COMPAREUNIT_2: Compare unit 2
1824   *                    @arg HRTIM_COMPAREUNIT_3: Compare unit 3
1825   *                    @arg HRTIM_COMPAREUNIT_4: Compare unit 4
1826   * @param  pCompareCfg: pointer to the compare unit configuration structure
1827   * @note When auto delayed mode is required for compare unit 2 or compare unit 4, 
1828   *       application has to configure separately the capture unit. Capture unit 
1829   *       to configure in that case depends on the compare unit auto delayed mode
1830   *       is applied to (see below):
1831   *         Auto delayed on output compare 2: capture unit 1 must be configured
1832   *         Auto delayed on output compare 4: capture unit 2 must be configured
1833   * @retval None
1834   */
1835  void HRTIM_WaveformCompareConfig(HRTIM_TypeDef * HRTIMx,
1836                                                   uint32_t TimerIdx,
1837                                                   uint32_t CompareUnit,
1838                                                   HRTIM_CompareCfgTypeDef* pCompareCfg)
1839 {
1840     uint32_t HRTIM_timcr;
1841
1842   /* Check parameters */
1843   assert_param(IS_HRTIM_TIMING_UNIT(TimerIdx));
1844   assert_param(IS_HRTIM_COMPAREUNIT_AUTODELAYEDMODE(CompareUnit, pCompareCfg->AutoDelayedMode));
1845   
1846   /* Configure the compare unit */
1847   switch (CompareUnit)
1848   {
1849     case HRTIM_COMPAREUNIT_1:
1850     {
1851       /* Set the compare value */
1852       HRTIMx->HRTIM_TIMERx[TimerIdx].CMP1xR = pCompareCfg->CompareValue;
1853     }
1854     break;
1855     case HRTIM_COMPAREUNIT_2:
1856     {
1857       /* Set the compare value */
1858       HRTIMx->HRTIM_TIMERx[TimerIdx].CMP2xR = pCompareCfg->CompareValue;
1859       
1860       if (pCompareCfg->AutoDelayedMode != HRTIM_AUTODELAYEDMODE_REGULAR)
1861       {
1862         /* Configure auto-delayed mode */
1863         HRTIM_timcr = HRTIMx->HRTIM_TIMERx[TimerIdx].TIMxCR;
1864         HRTIM_timcr &= ~HRTIM_TIMCR_DELCMP2;
1865         HRTIM_timcr |= pCompareCfg->AutoDelayedMode;
1866         HRTIMx->HRTIM_TIMERx[TimerIdx].TIMxCR = HRTIM_timcr;
1867         
1868         /* Set the compare value for timeout compare unit (if any) */
1869         if (pCompareCfg->AutoDelayedMode == HRTIM_AUTODELAYEDMODE_AUTODELAYED_TIMEOUTCMP1)
1870         {
1871           HRTIMx->HRTIM_TIMERx[TimerIdx].CMP1xR = pCompareCfg->AutoDelayedTimeout;
1872         }
1873         else if (pCompareCfg->AutoDelayedMode == HRTIM_AUTODELAYEDMODE_AUTODELAYED_TIMEOUTCMP3)
1874         {
1875           HRTIMx->HRTIM_TIMERx[TimerIdx].CMP3xR = pCompareCfg->AutoDelayedTimeout;
1876         }
1877       }
1878     }
1879     break;
1880     case HRTIM_COMPAREUNIT_3:
1881     {
1882       /* Set the compare value */
1883       HRTIMx->HRTIM_TIMERx[TimerIdx].CMP3xR = pCompareCfg->CompareValue;
1884     }
1885     break;
1886     case HRTIM_COMPAREUNIT_4:
1887     {
1888       /* Set the compare value */
1889       HRTIMx->HRTIM_TIMERx[TimerIdx].CMP4xR = pCompareCfg->CompareValue;
1890       
1891       if (pCompareCfg->AutoDelayedMode != HRTIM_AUTODELAYEDMODE_REGULAR)
1892       {
1893         /* Configure auto-delayed mode */
1894         HRTIM_timcr = HRTIMx->HRTIM_TIMERx[TimerIdx].TIMxCR;
1895         HRTIM_timcr &= ~HRTIM_TIMCR_DELCMP4;
1896         HRTIM_timcr |= (pCompareCfg->AutoDelayedMode << 2);
1897         HRTIMx->HRTIM_TIMERx[TimerIdx].TIMxCR = HRTIM_timcr;
1898         
1899         /* Set the compare value for timeout compare unit (if any) */
1900         if (pCompareCfg->AutoDelayedMode == HRTIM_AUTODELAYEDMODE_AUTODELAYED_TIMEOUTCMP1)
1901         {
1902           HRTIMx->HRTIM_TIMERx[TimerIdx].CMP1xR = pCompareCfg->AutoDelayedTimeout;
1903         }
1904         else if (pCompareCfg->AutoDelayedMode == HRTIM_AUTODELAYEDMODE_AUTODELAYED_TIMEOUTCMP3)
1905         {
1906           HRTIMx->HRTIM_TIMERx[TimerIdx].CMP3xR = pCompareCfg->AutoDelayedTimeout;
1907         }
1908       }
1909     }
1910     break;
1911     default:
1912     break;  
1913   }
1914 }
1915
1916 /**
1917   * @brief  Sets the HRTIMx Master Comparex Register value 
1918   * @param  HRTIMx: pointer to HRTIMx peripheral
1919   * @param  CompareUnit: Compare unit to configure
1920   *                    This parameter can be one of the following values: 
1921   *                    @arg HRTIM_COMPAREUNIT_1: Compare unit 1
1922   *                    @arg HRTIM_COMPAREUNIT_2: Compare unit 2
1923   *                    @arg HRTIM_COMPAREUNIT_3: Compare unit 3
1924   *                    @arg HRTIM_COMPAREUNIT_4: Compare unit 4
1925   * @param  Compare: specifies the Comparex register new value
1926   * @retval None
1927   */
1928 void HRTIM_MasterSetCompare(HRTIM_TypeDef * HRTIMx,
1929                                                   uint32_t CompareUnit,
1930                                                   uint32_t Compare)
1931 {
1932   /* Check parameters */
1933   assert_param(IS_HRTIM_COMPAREUNIT(CompareUnit));
1934   
1935   /* Configure the compare unit */
1936   switch (CompareUnit)
1937   {
1938     case HRTIM_COMPAREUNIT_1:
1939     {
1940       /* Set the compare value */
1941       HRTIMx->HRTIM_MASTER.MCMP1R = Compare;
1942     }
1943     break;
1944     case HRTIM_COMPAREUNIT_2:
1945     {
1946       /* Set the compare value */
1947       HRTIMx->HRTIM_MASTER.MCMP2R = Compare;
1948     }
1949     break;
1950     case HRTIM_COMPAREUNIT_3:
1951     {
1952       /* Set the compare value */
1953       HRTIMx->HRTIM_MASTER.MCMP3R = Compare;
1954     }
1955     break;
1956     case HRTIM_COMPAREUNIT_4:
1957     {
1958       /* Set the compare value */
1959       HRTIMx->HRTIM_MASTER.MCMP4R = Compare;
1960     }
1961     break;
1962     default:
1963     break;
1964   }  
1965 }
1966 /**
1967   * @brief  Configures the capture unit of a timer operating in waveform mode 
1968   * @param  HRTIMx: pointer to HRTIMx peripheral
1969   * @param  TimerIdx: Timer index
1970   *                   This parameter can be one of the following values:
1971   *                   @arg 0x0 to 0x4 for timers A to E 
1972   * @param  CaptureChannel: Capture unit to configure
1973   *                    This parameter can be one of the following values: 
1974   *                    @arg HRTIM_CAPTUREUNIT_1: Capture unit 1
1975   *                    @arg HRTIM_CAPTUREUNIT_2: Capture unit 2
1976   * @param  pCaptureCfg: pointer to the compare unit configuration structure
1977   * @retval None
1978   */
1979 void HRTIM_WaveformCaptureConfig(HRTIM_TypeDef * HRTIMx,
1980                                                   uint32_t TimerIdx,
1981                                                   uint32_t CaptureUnit,
1982                                                   HRTIM_CaptureCfgTypeDef* pCaptureCfg)
1983 {
1984   /* Configure the capture unit */
1985   switch (CaptureUnit)
1986   {
1987     case HRTIM_CAPTUREUNIT_1:
1988     {
1989       HRTIMx->HRTIM_TIMERx[TimerIdx].CPT1xCR = pCaptureCfg->Trigger;
1990     }
1991     break;
1992     case HRTIM_CAPTUREUNIT_2:
1993     {
1994       HRTIMx->HRTIM_TIMERx[TimerIdx].CPT2xCR = pCaptureCfg->Trigger;
1995     }
1996     break;
1997     default:
1998     break;
1999   }
2000 }
2001
2002 /**
2003   * @brief  Configures the output of a timer operating in waveform mode 
2004   * @param  HRTIMx: pointer to HRTIMx peripheral
2005   * @param  TimerIdx: Timer index
2006   *                   This parameter can be one of the following values:
2007   *                   @arg 0x0 to 0x4 for timers A to E 
2008   * @param  Output: Timer output
2009   *                    This parameter can be one of the following values:
2010   *                    @arg HRTIM_OUTPUT_TA1: Timer A - Output 1
2011   *                    @arg HRTIM_OUTPUT_TA2: Timer A - Output 2
2012   *                    @arg HRTIM_OUTPUT_TB1: Timer B - Output 1
2013   *                    @arg HRTIM_OUTPUT_TB2: Timer B - Output 2
2014   *                    @arg HRTIM_OUTPUT_TC1: Timer C - Output 1
2015   *                    @arg HRTIM_OUTPUT_TC2: Timer C - Output 2
2016   *                    @arg HRTIM_OUTPUT_TD1: Timer D - Output 1
2017   *                    @arg HRTIM_OUTPUT_TD2: Timer D - Output 2
2018   *                    @arg HRTIM_OUTPUT_TE1: Timer E - Output 1
2019   *                    @arg HRTIM_OUTPUT_TE2: Timer E - Output 2 
2020   * @param  pOutputCfg: pointer to the timer output configuration structure
2021   * @retval None
2022   */
2023 void HRTIM_WaveformOutputConfig(HRTIM_TypeDef * HRTIM_,
2024                                                 uint32_t TimerIdx,
2025                                                 uint32_t Output,
2026                                                 HRTIM_OutputCfgTypeDef * pOutputCfg)
2027 {
2028   /* Check parameters */
2029   assert_param(IS_HRTIM_TIMER_OUTPUT(TimerIdx, Output));
2030   assert_param(IS_HRTIM_OUTPUTPOLARITY(pOutputCfg->Polarity));
2031   assert_param(IS_HRTIM_OUTPUTIDLESTATE(pOutputCfg->IdleState));
2032   assert_param(IS_HRTIM_OUTPUTIDLEMODE(pOutputCfg->IdleMode));
2033   assert_param(IS_HRTIM_OUTPUTFAULTSTATE(pOutputCfg->FaultState));
2034   assert_param(IS_HRTIM_OUTPUTCHOPPERMODE(pOutputCfg->ChopperModeEnable));
2035   assert_param(IS_HRTIM_OUTPUTBURSTMODEENTRY(pOutputCfg->BurstModeEntryDelayed));
2036
2037   /* Configure the timer output */
2038   HRTIM_OutputConfig(HRTIM_, TimerIdx, Output, pOutputCfg);  
2039 }
2040
2041 /**
2042   * @brief  Configures the event filtering capabilities of a timer (blanking, windowing) 
2043   * @param  HRTIMx: pointer to HRTIMx peripheral
2044   * @param  TimerIdx: Timer index
2045   *                   This parameter can be one of the following values:
2046   *                   @arg 0x0 to 0x4 for timers A to E 
2047   * @param  Event: external event for which timer event filtering must be configured
2048   *                    This parameter can be one of the following values:
2049   *                    @arg HRTIM_EVENT_1: External event 1
2050   *                    @arg HRTIM_EVENT_2: External event 2
2051   *                    @arg HRTIM_EVENT_3: External event 3
2052   *                    @arg HRTIM_EVENT_4: External event 4
2053   *                    @arg HRTIM_EVENT_5: External event 5
2054   *                    @arg HRTIM_EVENT_6: External event 6
2055   *                    @arg HRTIM_EVENT_7: External event 7
2056   *                    @arg HRTIM_EVENT_8: External event 8
2057   *                    @arg HRTIM_EVENT_9: External event 9
2058   *                    @arg HRTIM_EVENT_10: External event 10
2059   * @param  pTimerEventFilteringCfg: pointer to the timer event filtering configuration structure
2060   * @retval None
2061   */
2062 void HRTIM_TimerEventFilteringConfig(HRTIM_TypeDef * HRTIMx,
2063                                                       uint32_t TimerIdx,
2064                                                       uint32_t Event,
2065                                                       HRTIM_TimerEventFilteringCfgTypeDef* pTimerEventFilteringCfg)
2066 {
2067   uint32_t HRTIM_eefr;
2068   
2069   /* Check parameters */
2070   assert_param(IS_HRTIM_TIMING_UNIT(TimerIdx));
2071   assert_param(IS_HRTIM_EVENT(Event));
2072   assert_param(IS_HRTIM_TIMEVENTFILTER(pTimerEventFilteringCfg->Filter));
2073   assert_param(IS_HRTIM_TIMEVENTLATCH(pTimerEventFilteringCfg->Latch));
2074
2075   /* Configure timer event filtering capabilities */
2076   switch (Event)
2077   {
2078     case HRTIM_TIMEVENTFILTER_NONE:
2079     {
2080       HRTIMx->HRTIM_TIMERx[TimerIdx].EEFxR1 = 0;
2081       HRTIMx->HRTIM_TIMERx[TimerIdx].EEFxR2 = 0;
2082     }
2083     break;
2084     case HRTIM_EVENT_1:
2085     {
2086       HRTIM_eefr = HRTIMx->HRTIM_TIMERx[TimerIdx].EEFxR1;
2087       HRTIM_eefr &= ~(HRTIM_EEFR1_EE1FLTR | HRTIM_EEFR1_EE1LTCH);
2088       HRTIM_eefr |= (pTimerEventFilteringCfg->Filter | pTimerEventFilteringCfg->Latch);
2089       HRTIMx->HRTIM_TIMERx[TimerIdx].EEFxR1 = HRTIM_eefr;
2090     }
2091     break;
2092     case HRTIM_EVENT_2:
2093     {
2094       HRTIM_eefr = HRTIMx->HRTIM_TIMERx[TimerIdx].EEFxR1;
2095       HRTIM_eefr &= ~(HRTIM_EEFR1_EE2FLTR | HRTIM_EEFR1_EE2LTCH);
2096       HRTIM_eefr |= ((pTimerEventFilteringCfg->Filter | pTimerEventFilteringCfg->Latch) << 6);
2097       HRTIMx->HRTIM_TIMERx[TimerIdx].EEFxR1 = HRTIM_eefr;
2098     }
2099     break;
2100     case HRTIM_EVENT_3:
2101     {
2102       HRTIM_eefr = HRTIMx->HRTIM_TIMERx[TimerIdx].EEFxR1;
2103       HRTIM_eefr &= ~(HRTIM_EEFR1_EE3FLTR | HRTIM_EEFR1_EE3LTCH);
2104       HRTIM_eefr |= ((pTimerEventFilteringCfg->Filter | pTimerEventFilteringCfg->Latch) << 12);
2105       HRTIMx->HRTIM_TIMERx[TimerIdx].EEFxR1 = HRTIM_eefr;
2106     }
2107     break;
2108     case HRTIM_EVENT_4:
2109     {
2110       HRTIM_eefr = HRTIMx->HRTIM_TIMERx[TimerIdx].EEFxR1;
2111       HRTIM_eefr &= ~(HRTIM_EEFR1_EE4FLTR | HRTIM_EEFR1_EE4LTCH);
2112       HRTIM_eefr |= ((pTimerEventFilteringCfg->Filter | pTimerEventFilteringCfg->Latch) << 18);
2113       HRTIMx->HRTIM_TIMERx[TimerIdx].EEFxR1 = HRTIM_eefr;
2114     }
2115     break;
2116     case HRTIM_EVENT_5:
2117     {
2118       HRTIM_eefr = HRTIMx->HRTIM_TIMERx[TimerIdx].EEFxR1;
2119       HRTIM_eefr &= ~(HRTIM_EEFR1_EE5FLTR | HRTIM_EEFR1_EE5LTCH);
2120       HRTIM_eefr |= ((pTimerEventFilteringCfg->Filter | pTimerEventFilteringCfg->Latch) << 24);
2121       HRTIMx->HRTIM_TIMERx[TimerIdx].EEFxR1 = HRTIM_eefr;
2122     }
2123     break;
2124     case HRTIM_EVENT_6:
2125     {
2126       HRTIM_eefr = HRTIMx->HRTIM_TIMERx[TimerIdx].EEFxR2;
2127       HRTIM_eefr &= ~(HRTIM_EEFR2_EE6FLTR | HRTIM_EEFR2_EE6LTCH);
2128       HRTIM_eefr |= (pTimerEventFilteringCfg->Filter | pTimerEventFilteringCfg->Latch);
2129       HRTIMx->HRTIM_TIMERx[TimerIdx].EEFxR2 = HRTIM_eefr;
2130     }
2131     break;
2132     case HRTIM_EVENT_7:
2133     {
2134       HRTIM_eefr = HRTIMx->HRTIM_TIMERx[TimerIdx].EEFxR2;
2135       HRTIM_eefr &= ~(HRTIM_EEFR2_EE7FLTR | HRTIM_EEFR2_EE7LTCH);
2136       HRTIM_eefr |= ((pTimerEventFilteringCfg->Filter | pTimerEventFilteringCfg->Latch) << 6);
2137       HRTIMx->HRTIM_TIMERx[TimerIdx].EEFxR2 = HRTIM_eefr;
2138     }
2139     break;
2140     case HRTIM_EVENT_8:
2141     {
2142       HRTIM_eefr = HRTIMx->HRTIM_TIMERx[TimerIdx].EEFxR2;
2143       HRTIM_eefr &= ~(HRTIM_EEFR2_EE8FLTR | HRTIM_EEFR2_EE8LTCH);
2144       HRTIM_eefr |= ((pTimerEventFilteringCfg->Filter | pTimerEventFilteringCfg->Latch) << 12);
2145       HRTIMx->HRTIM_TIMERx[TimerIdx].EEFxR2 = HRTIM_eefr;
2146     }
2147     break;
2148     case HRTIM_EVENT_9:
2149     {
2150       HRTIM_eefr = HRTIMx->HRTIM_TIMERx[TimerIdx].EEFxR2;
2151       HRTIM_eefr &= ~(HRTIM_EEFR2_EE9FLTR | HRTIM_EEFR2_EE9LTCH);
2152       HRTIM_eefr |= ((pTimerEventFilteringCfg->Filter | pTimerEventFilteringCfg->Latch) << 18);
2153       HRTIMx->HRTIM_TIMERx[TimerIdx].EEFxR2 = HRTIM_eefr;
2154     }
2155     break;
2156     case HRTIM_EVENT_10:
2157     {
2158       HRTIM_eefr = HRTIMx->HRTIM_TIMERx[TimerIdx].EEFxR2;
2159       HRTIM_eefr &= ~(HRTIM_EEFR2_EE10FLTR | HRTIM_EEFR2_EE10LTCH);
2160       HRTIM_eefr |= ((pTimerEventFilteringCfg->Filter | pTimerEventFilteringCfg->Latch) << 24);
2161       HRTIMx->HRTIM_TIMERx[TimerIdx].EEFxR2 = HRTIM_eefr;
2162     }
2163     break;
2164     default:
2165     break;
2166   }
2167 }
2168
2169 /**
2170   * @brief  Configures the dead time insertion feature for a timer 
2171   * @param  HRTIMx: pointer to HRTIMx peripheral
2172   * @param  TimerIdx: Timer index
2173   *                   This parameter can be one of the following values:
2174   *                   @arg 0x0 to 0x4 for timers A to E 
2175   * @param  pDeadTimeCfg: pointer to the dead time insertion configuration structure
2176   * @retval None
2177   */
2178 void HRTIM_DeadTimeConfig(HRTIM_TypeDef * HRTIMx,
2179                                            uint32_t TimerIdx,
2180                                            HRTIM_DeadTimeCfgTypeDef* pDeadTimeCfg)
2181 {
2182   uint32_t HRTIM_dtr;
2183   
2184   /* Check parameters */
2185   assert_param(IS_HRTIM_TIMING_UNIT(TimerIdx));
2186   assert_param(IS_HRTIM_TIMDEADTIME_RISINGSIGN(pDeadTimeCfg->RisingSign));
2187   assert_param(IS_HRTIM_TIMDEADTIME_RISINGLOCK(pDeadTimeCfg->RisingLock));
2188   assert_param(IS_HRTIM_TIMDEADTIME_RISINGSIGNLOCK(pDeadTimeCfg->RisingSignLock));
2189   assert_param(IS_HRTIM_TIMDEADTIME_FALLINGSIGN(pDeadTimeCfg->FallingSign));
2190   assert_param(IS_HRTIM_TIMDEADTIME_FALLINGLOCK(pDeadTimeCfg->FallingLock));
2191   assert_param(IS_HRTIM_TIMDEADTIME_FALLINGSIGNLOCK(pDeadTimeCfg->FallingSignLock));
2192
2193   HRTIM_dtr = HRTIMx->HRTIM_TIMERx[TimerIdx].DTxR;
2194      
2195   /* Clear timer dead times configuration */
2196   HRTIM_dtr &= ~(HRTIM_DTR_DTR | HRTIM_DTR_SDTR | HRTIM_DTR_DTPRSC |
2197                  HRTIM_DTR_DTRSLK | HRTIM_DTR_DTRLK | HRTIM_DTR_SDTF |
2198                  HRTIM_DTR_SDTR | HRTIM_DTR_DTFSLK | HRTIM_DTR_DTFLK);
2199   
2200   /* Set timer dead times configuration */
2201   HRTIM_dtr |= (pDeadTimeCfg->Prescaler << 10);
2202   HRTIM_dtr |= pDeadTimeCfg->RisingValue;
2203   HRTIM_dtr |= pDeadTimeCfg->RisingSign;
2204   HRTIM_dtr |= pDeadTimeCfg->RisingSignLock;
2205   HRTIM_dtr |= pDeadTimeCfg->RisingLock;
2206   HRTIM_dtr |= (pDeadTimeCfg->FallingValue << 16);
2207   HRTIM_dtr |= pDeadTimeCfg->FallingSign;
2208   HRTIM_dtr |= pDeadTimeCfg->FallingSignLock;
2209   HRTIM_dtr |= pDeadTimeCfg->FallingLock;
2210     
2211   /* Update the HRTIMx registers */  
2212   HRTIMx->HRTIM_TIMERx[TimerIdx].DTxR = HRTIM_dtr;
2213 }
2214
2215 /**
2216   * @brief  Configures the chopper mode feature for a timer 
2217   * @param  HRTIMx: pointer to HRTIMx peripheral
2218   * @param  TimerIdx: Timer index
2219   *                   This parameter can be one of the following values:
2220   *                   @arg 0x0 to 0x4 for timers A to E 
2221   * @param  pChopperModeCfg: pointer to the chopper mode configuration structure
2222   * @retval None
2223   */
2224 void HRTIM_ChopperModeConfig(HRTIM_TypeDef * HRTIMx,
2225                                               uint32_t TimerIdx,
2226                                               HRTIM_ChopperModeCfgTypeDef* pChopperModeCfg)
2227 {
2228   uint32_t HRTIM_chpr;
2229   
2230   /* Check parameters */
2231   assert_param(IS_HRTIM_TIMING_UNIT(TimerIdx));
2232
2233   HRTIM_chpr = HRTIMx->HRTIM_TIMERx[TimerIdx].CHPxR;
2234      
2235   /* Clear timer chopper mode configuration */
2236   HRTIM_chpr &= ~(HRTIM_CHPR_CARFRQ | HRTIM_CHPR_CARDTY | HRTIM_CHPR_STRPW);
2237   
2238   /* Set timer chopper mode configuration */
2239   HRTIM_chpr |= pChopperModeCfg->CarrierFreq;
2240   HRTIM_chpr |= (pChopperModeCfg->DutyCycle << 4);
2241   HRTIM_chpr |= (pChopperModeCfg->StartPulse << 7);
2242     
2243   /* Update the HRTIMx registers */  
2244   HRTIMx->HRTIM_TIMERx[TimerIdx].CHPxR = HRTIM_chpr;
2245 }
2246
2247 /**
2248   * @brief  Configures the burst DMA controller for a timer 
2249   * @param  HRTIMx: pointer to HRTIMx peripheral
2250   * @param  TimerIdx: Timer index
2251    *                  This parameter can be one of the following values:
2252  *                    @arg 0x5 for master timer
2253   *                   @arg 0x0 to 0x4 for timers A to E 
2254   * @param  RegistersToUpdate: registers to be written by DMA
2255   *                    This parameter can be any combination of the following values:
2256   *                    @arg HRTIM_BURSTDMA_CR: HRTIM_MCR or HRTIM_TIMxCR
2257   *                    @arg HRTIM_BURSTDMA_ICR: HRTIM_MICR or HRTIM_TIMxICR
2258   *                    @arg HRTIM_BURSTDMA_DIER: HRTIM_MDIER or HRTIM_TIMxDIER
2259   *                    @arg HRTIM_BURSTDMA_CNT: HRTIM_MCNT or HRTIM_TIMxCNT
2260   *                    @arg HRTIM_BURSTDMA_PER: HRTIM_MPER or HRTIM_TIMxPER
2261   *                    @arg HRTIM_BURSTDMA_REP: HRTIM_MREP or HRTIM_TIMxREP
2262   *                    @arg HRTIM_BURSTDMA_CMP1: HRTIM_MCMP1 or HRTIM_TIMxCMP1
2263   *                    @arg HRTIM_BURSTDMA_CMP2: HRTIM_MCMP2 or HRTIM_TIMxCMP2
2264   *                    @arg HRTIM_BURSTDMA_CMP3: HRTIM_MCMP3 or HRTIM_TIMxCMP3
2265   *                    @arg HRTIM_BURSTDMA_CMP4: HRTIM_MCMP4 or HRTIM_TIMxCMP4
2266   *                    @arg HRTIM_BURSTDMA_DTR: HRTIM_TIMxDTR
2267   *                    @arg HRTIM_BURSTDMA_SET1R: HRTIM_TIMxSET1R
2268   *                    @arg HRTIM_BURSTDMA_RST1R: HRTIM_TIMxRST1R
2269   *                    @arg HRTIM_BURSTDMA_SET2R: HRTIM_TIMxSET2R
2270   *                    @arg HRTIM_BURSTDMA_RST2R: HRTIM_TIMxRST2R
2271   *                    @arg HRTIM_BURSTDMA_EEFR1: HRTIM_TIMxEEFR1
2272   *                    @arg HRTIM_BURSTDMA_EEFR2: HRTIM_TIMxEEFR2
2273   *                    @arg HRTIM_BURSTDMA_RSTR: HRTIM_TIMxRSTR
2274   *                    @arg HRTIM_BURSTDMA_CHPR: HRTIM_TIMxCHPR
2275   *                    @arg HRTIM_BURSTDMA_OUTR: HRTIM_TIMxOUTR
2276   *                    @arg HRTIM_BURSTDMA_FLTR: HRTIM_TIMxFLTR
2277   * @retval None
2278   */
2279 void HRTIM_BurstDMAConfig(HRTIM_TypeDef * HRTIMx,
2280                                            uint32_t TimerIdx,
2281                                            uint32_t RegistersToUpdate)
2282 {
2283   /* Check parameters */
2284   assert_param(IS_HRTIM_TIMER_BURSTDMA(TimerIdx, RegistersToUpdate));
2285   
2286   /* Set the burst DMA timer update register */
2287   switch (TimerIdx) 
2288   {
2289     case HRTIM_TIMERINDEX_TIMER_A:
2290     {
2291       HRTIMx->HRTIM_COMMON.BDTAUPR = RegistersToUpdate;
2292     }
2293     break;
2294     case HRTIM_TIMERINDEX_TIMER_B:
2295     {
2296       HRTIMx->HRTIM_COMMON.BDTBUPR = RegistersToUpdate;
2297     }
2298     break;
2299     case HRTIM_TIMERINDEX_TIMER_C:
2300     {
2301       HRTIMx->HRTIM_COMMON.BDTCUPR = RegistersToUpdate;
2302     }
2303     break;
2304     case HRTIM_TIMERINDEX_TIMER_D:
2305     {
2306       HRTIMx->HRTIM_COMMON.BDTDUPR = RegistersToUpdate;
2307     }
2308     break;
2309     case HRTIM_TIMERINDEX_TIMER_E:
2310     {
2311       HRTIMx->HRTIM_COMMON.BDTEUPR = RegistersToUpdate;
2312     }
2313     break;
2314     case HRTIM_TIMERINDEX_MASTER:
2315     {
2316       HRTIMx->HRTIM_COMMON.BDMUPDR = RegistersToUpdate;
2317     }
2318     break;
2319     default:
2320     break;
2321   }
2322 }
2323
2324 /**
2325   * @brief  Configures the external input/output synchronization of the HRTIMx 
2326   * @param  HRTIMx: pointer to HRTIMx peripheral
2327   * @param  pSynchroCfg: pointer to the input/output synchronization configuration structure
2328   * @retval None
2329   */
2330 void HRTIM_SynchronizationConfig(HRTIM_TypeDef *HRTIMx, HRTIM_SynchroCfgTypeDef * pSynchroCfg)
2331 {
2332   uint32_t HRTIM_mcr;
2333   
2334   /* Check parameters */
2335   assert_param(IS_HRTIM_SYNCINPUTSOURCE(pSynchroCfg->SyncInputSource));
2336   assert_param(IS_HRTIM_SYNCOUTPUTSOURCE(pSynchroCfg->SyncOutputSource));
2337   assert_param(IS_HRTIM_SYNCOUTPUTPOLARITY(pSynchroCfg->SyncOutputPolarity));
2338     
2339   HRTIM_mcr = HRTIMx->HRTIM_MASTER.MCR;
2340
2341   /* Set the synchronization input source */
2342   HRTIM_mcr &= ~(HRTIM_MCR_SYNC_IN);
2343   HRTIM_mcr |= pSynchroCfg->SyncInputSource;
2344   
2345   /* Set the event to be sent on the synchronization output */
2346   HRTIM_mcr &= ~(HRTIM_MCR_SYNC_SRC);
2347   HRTIM_mcr |= pSynchroCfg->SyncOutputSource;
2348   
2349   /* Set the polarity of the synchronization output */
2350   HRTIM_mcr &= ~(HRTIM_MCR_SYNC_OUT);
2351   HRTIM_mcr |= pSynchroCfg->SyncOutputPolarity;
2352   
2353   /* Update the HRTIMx registers */  
2354   HRTIMx->HRTIM_MASTER.MCR = HRTIM_mcr;
2355 }
2356
2357 /**
2358   * @brief  Configures the burst mode feature of the HRTIMx 
2359   * @param  HRTIMx: pointer to HRTIMx peripheral
2360   * @param  pBurstModeCfg: pointer to the burst mode configuration structure
2361   * @retval None
2362   */
2363 void HRTIM_BurstModeConfig(HRTIM_TypeDef * HRTIMx,
2364                                             HRTIM_BurstModeCfgTypeDef* pBurstModeCfg)
2365 {
2366   uint32_t HRTIM_bmcr;
2367
2368   /* Check parameters */
2369   assert_param(IS_HRTIM_BURSTMODE(pBurstModeCfg->Mode));
2370   assert_param(IS_HRTIM_BURSTMODECLOCKSOURCE(pBurstModeCfg->ClockSource));
2371   assert_param(IS_HRTIM_HRTIM_BURSTMODEPRESCALER(pBurstModeCfg->Prescaler));
2372   assert_param(IS_HRTIM_BURSTMODEPRELOAD(pBurstModeCfg->PreloadEnable));
2373   
2374   HRTIM_bmcr = HRTIMx->HRTIM_COMMON.BMCR;
2375
2376   /* Set the burst mode operating mode */
2377   HRTIM_bmcr &= ~(HRTIM_BMCR_BMOM);
2378   HRTIM_bmcr |= pBurstModeCfg->Mode;
2379   
2380   /* Set the burst mode clock source */
2381   HRTIM_bmcr &= ~(HRTIM_BMCR_BMCLK);
2382   HRTIM_bmcr |= pBurstModeCfg->ClockSource;
2383   
2384   /* Set the burst mode prescaler */
2385   HRTIM_bmcr &= ~(HRTIM_BMCR_BMPSC);
2386   HRTIM_bmcr |= pBurstModeCfg->Prescaler;
2387  
2388   /* Enable/disable burst mode registers preload */
2389   HRTIM_bmcr &= ~(HRTIM_BMCR_BMPREN);
2390   HRTIM_bmcr |= pBurstModeCfg->PreloadEnable;
2391  
2392   /* Set the burst mode trigger */
2393   HRTIMx->HRTIM_COMMON.BMTRGR = pBurstModeCfg->Trigger;
2394   
2395   /* Set the burst mode compare value */
2396   HRTIMx->HRTIM_COMMON.BMCMPR = pBurstModeCfg->IdleDuration;
2397   
2398   /* Set the burst mode period */
2399   HRTIMx->HRTIM_COMMON.BMPER = pBurstModeCfg->Period;
2400   
2401   /* Update the HRTIMx registers */  
2402   HRTIMx->HRTIM_COMMON.BMCR = HRTIM_bmcr;
2403 }
2404
2405 /**
2406   * @brief  Configures the conditioning of an external event
2407   * @param  HRTIMx: pointer to HRTIMx peripheral
2408   * @param  Event: external event to configure
2409   *                    This parameter can be one of the following values:
2410   *                    @arg HRTIM_EVENT_1: External event 1
2411   *                    @arg HRTIM_EVENT_2: External event 2
2412   *                    @arg HRTIM_EVENT_3: External event 3
2413   *                    @arg HRTIM_EVENT_4: External event 4
2414   *                    @arg HRTIM_EVENT_5: External event 5
2415   *                    @arg HRTIM_EVENT_6: External event 6
2416   *                    @arg HRTIM_EVENT_7: External event 7
2417   *                    @arg HRTIM_EVENT_8: External event 8
2418   *                    @arg HRTIM_EVENT_9: External event 9
2419   *                    @arg HRTIM_EVENT_10: External event 10
2420   * @param  pEventCfg: pointer to the event conditioning configuration structure
2421   * @retval None
2422   */
2423 void HRTIM_EventConfig(HRTIM_TypeDef * HRTIMx,
2424                                         uint32_t Event,
2425                                         HRTIM_EventCfgTypeDef* pEventCfg)
2426 {
2427   /* Check parameters */
2428   assert_param(IS_HRTIM_EVENTSRC(pEventCfg->Source)); 
2429   assert_param(IS_HRTIM_EVENTPOLARITY(pEventCfg->Polarity)); 
2430   assert_param(IS_HRTIM_EVENTSENSITIVITY(pEventCfg->Sensitivity)); 
2431   assert_param(IS_HRTIM_EVENTFASTMODE(pEventCfg->FastMode)); 
2432   assert_param(IS_HRTIM_EVENTFILTER(pEventCfg->Filter)); 
2433
2434   /* Configure the event channel */
2435   HRTIM_ExternalEventConfig(HRTIMx, Event, pEventCfg);
2436  
2437 }
2438
2439 /**
2440   * @brief  Configures the external event conditioning block prescaler
2441   * @param  HRTIMx: pointer to HRTIMx peripheral
2442   * @param  Prescaler: Prescaler value
2443   *                    This parameter can be one of the following values:
2444   *                    @arg HRTIM_EVENTPRESCALER_DIV1: fEEVS=fHRTIMx
2445   *                    @arg HRTIM_EVENTPRESCALER_DIV2: fEEVS=fHRTIMx / 2
2446   *                    @arg HRTIM_EVENTPRESCALER_DIV4: fEEVS=fHRTIMx / 4
2447   *                    @arg HRTIM_EVENTPRESCALER_DIV8: fEEVS=fHRTIMx / 8
2448   * @retval None
2449   */
2450 void HRTIM_EventPrescalerConfig(HRTIM_TypeDef * HRTIMx,
2451                                                  uint32_t Prescaler)
2452 {
2453   uint32_t HRTIM_eecr3;
2454
2455   /* Check parameters */
2456   assert_param(IS_HRTIM_EVENTPRESCALER(Prescaler));
2457
2458   /* Set the external event prescaler */
2459   HRTIM_eecr3 = HRTIMx->HRTIM_COMMON.EECR3;
2460   HRTIM_eecr3 &= ~(HRTIM_EECR3_EEVSD);
2461   HRTIM_eecr3 |= Prescaler;
2462   
2463   /* Update the HRTIMx registers */
2464   HRTIMx->HRTIM_COMMON.EECR3 = HRTIM_eecr3;
2465 }
2466  
2467 /**
2468   * @brief  Configures the conditioning of fault input
2469   * @param  HRTIMx: pointer to HRTIMx peripheral
2470   * @param  Fault: fault input to configure
2471   *                    This parameter can be one of the following values:
2472   *                    @arg HRTIM_FAULT_1: Fault input 1
2473   *                    @arg HRTIM_FAULT_2: Fault input 2
2474   *                    @arg HRTIM_FAULT_3: Fault input 3
2475   *                    @arg HRTIM_FAULT_4: Fault input 4
2476   *                    @arg HRTIM_FAULT_5: Fault input 5
2477   * @param  pFaultCfg: pointer to the fault conditioning configuration structure
2478   * @retval None
2479   */
2480 void HRTIM_FaultConfig(HRTIM_TypeDef * HRTIMx,
2481                                         HRTIM_FaultCfgTypeDef* pFaultCfg,
2482                                         uint32_t Fault)
2483 {
2484   uint32_t HRTIM_fltinr1;
2485   uint32_t HRTIM_fltinr2;
2486
2487   /* Check parameters */
2488   assert_param(IS_HRTIM_FAULT(Fault));
2489   assert_param(IS_HRTIM_FAULTSOURCE(pFaultCfg->Source));
2490   assert_param(IS_HRTIM_FAULTPOLARITY(pFaultCfg->Polarity));
2491   assert_param(IS_HRTIM_FAULTFILTER(pFaultCfg->Filter));
2492   assert_param(IS_HRTIM_FAULTLOCK(pFaultCfg->Lock));
2493
2494   /* Configure fault channel */
2495   HRTIM_fltinr1 = HRTIMx->HRTIM_COMMON.FLTINxR1;
2496   HRTIM_fltinr2 = HRTIMx->HRTIM_COMMON.FLTINxR2;
2497   
2498   switch (Fault)
2499   {
2500     case HRTIM_FAULT_1:
2501     {
2502       HRTIM_fltinr1 &= ~(HRTIM_FLTINR1_FLT1P | HRTIM_FLTINR1_FLT1SRC | HRTIM_FLTINR1_FLT1F | HRTIM_FLTINR1_FLT1LCK);
2503       HRTIM_fltinr1 |= pFaultCfg->Polarity;
2504       HRTIM_fltinr1 |= pFaultCfg->Source;
2505       HRTIM_fltinr1 |= pFaultCfg->Filter;
2506       HRTIM_fltinr1 |= pFaultCfg->Lock;
2507     }
2508     break;
2509     case HRTIM_FAULT_2:
2510     {
2511       HRTIM_fltinr1 &= ~(HRTIM_FLTINR1_FLT2P | HRTIM_FLTINR1_FLT2SRC | HRTIM_FLTINR1_FLT2F | HRTIM_FLTINR1_FLT2LCK);
2512       HRTIM_fltinr1 |= (pFaultCfg->Polarity << 8);
2513       HRTIM_fltinr1 |= (pFaultCfg->Source << 8);
2514       HRTIM_fltinr1 |= (pFaultCfg->Filter << 8);
2515       HRTIM_fltinr1 |= (pFaultCfg->Lock << 8);
2516     }
2517     break;
2518     case HRTIM_FAULT_3:
2519     {
2520       HRTIM_fltinr1 &= ~(HRTIM_FLTINR1_FLT3P | HRTIM_FLTINR1_FLT3SRC | HRTIM_FLTINR1_FLT3F | HRTIM_FLTINR1_FLT3LCK);
2521       HRTIM_fltinr1 |= (pFaultCfg->Polarity << 16);
2522       HRTIM_fltinr1 |= (pFaultCfg->Source << 16);
2523       HRTIM_fltinr1 |= (pFaultCfg->Filter << 16);
2524       HRTIM_fltinr1 |= (pFaultCfg->Lock << 16);
2525     }
2526     break;
2527     case HRTIM_FAULT_4:
2528     {
2529       HRTIM_fltinr1 &= ~(HRTIM_FLTINR1_FLT4P | HRTIM_FLTINR1_FLT4SRC | HRTIM_FLTINR1_FLT4F | HRTIM_FLTINR1_FLT4LCK);
2530       HRTIM_fltinr1 |= (pFaultCfg->Polarity << 24);
2531       HRTIM_fltinr1 |= (pFaultCfg->Source << 24);
2532       HRTIM_fltinr1 |= (pFaultCfg->Filter << 24);
2533       HRTIM_fltinr1 |= (pFaultCfg->Lock << 24);
2534     }
2535     break;
2536     case HRTIM_FAULT_5:
2537     {
2538       HRTIM_fltinr2 &= ~(HRTIM_FLTINR2_FLT5P | HRTIM_FLTINR2_FLT5SRC | HRTIM_FLTINR2_FLT5F | HRTIM_FLTINR2_FLT5LCK);
2539       HRTIM_fltinr2 |= pFaultCfg->Polarity;
2540       HRTIM_fltinr2 |= pFaultCfg->Source;
2541       HRTIM_fltinr2 |= pFaultCfg->Filter;
2542       HRTIM_fltinr2 |= pFaultCfg->Lock;
2543     }
2544     break;
2545     default:
2546     break;
2547   }
2548
2549   /* Update the HRTIMx registers */
2550   HRTIMx->HRTIM_COMMON.FLTINxR1 = HRTIM_fltinr1;
2551   HRTIMx->HRTIM_COMMON.FLTINxR2 = HRTIM_fltinr2;
2552 }
2553
2554 /**
2555   * @brief  Configures the fault conditioning block prescaler
2556   * @param  HRTIMx: pointer to HRTIMx peripheral
2557   * @param  Prescaler: Prescaler value
2558   *                    This parameter can be one of the following values:
2559   *                    @arg HRTIM_FAULTPRESCALER_DIV1: fFLTS=fHRTIMx
2560   *                    @arg HRTIM_FAULTPRESCALER_DIV2: fFLTS=fHRTIMx / 2
2561   *                    @arg HRTIM_FAULTPRESCALER_DIV4: fFLTS=fHRTIMx / 4
2562   *                    @arg HRTIM_FAULTPRESCALER_DIV8: fFLTS=fHRTIMx / 8
2563   * @retval None
2564   */
2565 void HRTIM_FaultPrescalerConfig(HRTIM_TypeDef * HRTIMx,
2566                                                  uint32_t Prescaler)
2567 {
2568   uint32_t HRTIM_fltinr2;
2569
2570   /* Check parameters */
2571   assert_param(IS_HRTIM_FAULTPRESCALER(Prescaler));
2572   
2573   /* Set the external event prescaler */
2574   HRTIM_fltinr2 = HRTIMx->HRTIM_COMMON.FLTINxR2;
2575   HRTIM_fltinr2 &= ~(HRTIM_FLTINR2_FLTSD);
2576   HRTIM_fltinr2 |= Prescaler;
2577   
2578   /* Update the HRTIMx registers */
2579   HRTIMx->HRTIM_COMMON.FLTINxR2 = HRTIM_fltinr2;
2580 }
2581
2582 /**
2583   * @brief  Enables or disables the HRTIMx Fault mode.
2584   * @param  HRTIMx: pointer to HRTIMx peripheral
2585   * @param  Fault: fault input to configure
2586   *                    This parameter can be one of the following values:
2587   *                    @arg HRTIM_FAULT_1: Fault input 1
2588   *                    @arg HRTIM_FAULT_2: Fault input 2
2589   *                    @arg HRTIM_FAULT_3: Fault input 3
2590   *                    @arg HRTIM_FAULT_4: Fault input 4
2591   *                    @arg HRTIM_FAULT_5: Fault input 5
2592   * @param  Enable: Fault mode controller enabling
2593   *                    This parameter can be one of the following values:
2594   *                    @arg HRTIM_FAULT_ENABLED: Fault mode enabled
2595   *                    @arg HRTIM_FAULT_DISABLED: Fault mode disabled
2596   * @retval None
2597   */
2598 void HRTIM_FaultModeCtl(HRTIM_TypeDef * HRTIMx, uint32_t Fault, uint32_t Enable)
2599 {
2600   uint32_t HRTIM_fltinr1;
2601   uint32_t HRTIM_fltinr2;
2602   
2603   /* Check parameters */
2604   assert_param(IS_HRTIM_FAULT(Fault));
2605   assert_param(IS_HRTIM_FAULTCTL(Enable));
2606
2607   /* Configure fault channel */
2608   HRTIM_fltinr1 = HRTIMx->HRTIM_COMMON.FLTINxR1;
2609   HRTIM_fltinr2 = HRTIMx->HRTIM_COMMON.FLTINxR2;
2610   
2611   switch (Fault)
2612   {
2613     case HRTIM_FAULT_1:
2614     {
2615       HRTIM_fltinr1 &= ~HRTIM_FLTINR1_FLT1E;
2616       HRTIM_fltinr1 |= Enable;
2617     }
2618     break;
2619     case HRTIM_FAULT_2:
2620     {
2621       HRTIM_fltinr1 &= ~HRTIM_FLTINR1_FLT2E;
2622       HRTIM_fltinr1 |= (Enable<< 8);
2623     }
2624     break;
2625     case HRTIM_FAULT_3:
2626     {
2627       HRTIM_fltinr1 &= ~HRTIM_FLTINR1_FLT3E;
2628       HRTIM_fltinr1 |= (Enable << 16);
2629     }
2630     break;
2631     case HRTIM_FAULT_4:
2632     {
2633       HRTIM_fltinr1 &= ~HRTIM_FLTINR1_FLT4E; 
2634       HRTIM_fltinr1 |= (Enable << 24);
2635     }
2636     break;
2637     case HRTIM_FAULT_5:
2638     {
2639       HRTIM_fltinr2 &= ~HRTIM_FLTINR2_FLT5E;
2640       HRTIM_fltinr2 |= Enable;
2641     }
2642     break;
2643     default:
2644     break;
2645   }
2646
2647   /* Update the HRTIMx registers */
2648   HRTIMx->HRTIM_COMMON.FLTINxR1 = HRTIM_fltinr1;
2649   HRTIMx->HRTIM_COMMON.FLTINxR2 = HRTIM_fltinr2;
2650 }                              
2651
2652 /**
2653   * @brief  Configures both the ADC trigger register update source and the ADC
2654   *         trigger source.
2655   * @param  HRTIMx: pointer to HRTIMx peripheral
2656   * @param  ADC trigger: ADC trigger to configure
2657   *                    This parameter can be one of the following values:
2658   *                    @arg HRTIM_ADCTRIGGER_1: ADC trigger 1
2659   *                    @arg HRTIM_ADCTRIGGER_2: ADC trigger 2
2660   *                    @arg HRTIM_ADCTRIGGER_3: ADC trigger 3
2661   *                    @arg HRTIM_ADCTRIGGER_4: ADC trigger 4
2662   * @param  pADCTriggerCfg: pointer to the ADC trigger configuration structure
2663   * @retval None
2664   */
2665 void HRTIM_ADCTriggerConfig(HRTIM_TypeDef * HRTIMx,
2666                                              uint32_t ADCTrigger,
2667                                              HRTIM_ADCTriggerCfgTypeDef* pADCTriggerCfg)
2668 {
2669   uint32_t HRTIM_cr1;
2670   
2671   /* Check parameters */
2672   assert_param(IS_HRTIM_ADCTRIGGER(ADCTrigger));
2673   assert_param(IS_HRTIM_ADCTRIGGERUPDATE(pADCTriggerCfg->UpdateSource));
2674
2675   /* Set the ADC trigger update source */
2676   HRTIM_cr1 = HRTIMx->HRTIM_COMMON.CR1;
2677   
2678   switch (ADCTrigger)
2679   {
2680     case HRTIM_ADCTRIGGER_1:
2681     {
2682       HRTIM_cr1 &= ~(HRTIM_CR1_ADC1USRC);
2683       HRTIM_cr1 |= pADCTriggerCfg->UpdateSource;
2684       
2685       /* Set the ADC trigger 1 source */
2686       HRTIMx->HRTIM_COMMON.ADC1R = pADCTriggerCfg->Trigger;
2687     }
2688     break;
2689     case HRTIM_ADCTRIGGER_2:
2690     {
2691       HRTIM_cr1 &= ~(HRTIM_CR1_ADC2USRC);
2692       HRTIM_cr1 |= (pADCTriggerCfg->UpdateSource << 3); 
2693
2694       /* Set the ADC trigger 2 source */
2695       HRTIMx->HRTIM_COMMON.ADC2R = pADCTriggerCfg->Trigger;
2696     }
2697     break;
2698     case HRTIM_ADCTRIGGER_3:
2699     {
2700       HRTIM_cr1 &= ~(HRTIM_CR1_ADC3USRC);
2701       HRTIM_cr1 |= (pADCTriggerCfg->UpdateSource << 6); 
2702       
2703       /* Set the ADC trigger 3 source */
2704       HRTIMx->HRTIM_COMMON.ADC3R = pADCTriggerCfg->Trigger;
2705     }
2706     case HRTIM_ADCTRIGGER_4:
2707     {
2708       HRTIM_cr1 &= ~(HRTIM_CR1_ADC4USRC);
2709       HRTIM_cr1 |= (pADCTriggerCfg->UpdateSource << 9); 
2710       
2711       /* Set the ADC trigger 4 source */
2712       HRTIMx->HRTIM_COMMON.ADC4R = pADCTriggerCfg->Trigger;
2713     }
2714     break;
2715     default:
2716     break;
2717   }
2718   
2719   /* Update the HRTIMx registers */
2720   HRTIMx->HRTIM_COMMON.CR1 = HRTIM_cr1;
2721 }
2722
2723
2724 /**
2725   * @brief  Enables or disables the HRTIMx burst mode controller.
2726   * @param  HRTIMx: pointer to HRTIMx peripheral
2727   * @param  Enable: Burst mode controller enabling
2728   *                    This parameter can be one of the following values:
2729   *                    @arg HRTIM_BURSTMODECTL_ENABLED: Burst mode enabled
2730   *                    @arg HRTIM_BURSTMODECTL_DISABLED: Burst mode disabled
2731   * @retval None
2732   */
2733 void HRTIM_BurstModeCtl(HRTIM_TypeDef * HRTIMx, uint32_t Enable)
2734 {
2735   uint32_t HRTIM_bmcr;
2736   
2737   /* Check parameters */
2738   assert_param(IS_HRTIM_BURSTMODECTL(Enable));
2739   
2740   /* Enable/Disable the burst mode controller */
2741   HRTIM_bmcr = HRTIMx->HRTIM_COMMON.BMCR;
2742   HRTIM_bmcr &= ~(HRTIM_BMCR_BME);
2743   HRTIM_bmcr |= Enable;
2744   
2745   /* Update the HRTIMx registers */
2746   HRTIMx->HRTIM_COMMON.BMCR = HRTIM_bmcr;
2747 }
2748
2749 /**
2750   * @brief  Triggers a software capture on the designed capture unit
2751   * @param  HRTIMx: pointer to HRTIMx peripheral
2752   * @param  TimerIdx: Timer index
2753   *                   This parameter can be one of the following values:
2754   *                   @arg 0x0 to 0x4 for timers A to E 
2755   * @param  CaptureUnit: Capture unit to trig
2756   *                    This parameter can be one of the following values: 
2757   *                    @arg HRTIM_CAPTUREUNIT_1: Capture unit 1
2758   *                    @arg HRTIM_CAPTUREUNIT_2: Capture unit 2
2759   * @retval None
2760   * @note The 'software capture' bit in the capure configuration register is
2761   *       automatically reset by hardware
2762   */
2763 void HRTIM_SoftwareCapture(HRTIM_TypeDef * HRTIMx,
2764                                             uint32_t TimerIdx,
2765                                             uint32_t CaptureUnit)
2766 {
2767   /* Check parameters */
2768   assert_param(IS_HRTIM_TIMING_UNIT(TimerIdx));
2769   assert_param(IS_HRTIM_CAPTUREUNIT(CaptureUnit));
2770   
2771   /* Force a software capture on concerned capture unit */
2772   switch (CaptureUnit)
2773   {
2774     case HRTIM_CAPTUREUNIT_1:
2775     {
2776       HRTIMx->HRTIM_TIMERx[TimerIdx].CPT1xCR |= HRTIM_CPT1CR_SWCPT;
2777     }
2778     break;
2779     case HRTIM_CAPTUREUNIT_2:
2780     {
2781       HRTIMx->HRTIM_TIMERx[TimerIdx].CPT2xCR |= HRTIM_CPT2CR_SWCPT;
2782     }
2783     break;
2784     default:
2785     break;
2786   }
2787 }
2788
2789 /**
2790   * @brief  Triggers the update of the registers of one or several timers
2791   * @param  HRTIMx: pointer to HRTIMx peripheral
2792   * @param  TimersToUpdate: timers concerned with the software register update
2793   *                   This parameter can be any combination of the following values:
2794   *                   @arg HRTIM_TIMERUPDATE_MASTER 
2795   *                   @arg HRTIM_TIMERUPDATE_A 
2796   *                   @arg HRTIM_TIMERUPDATE_B 
2797   *                   @arg HRTIM_TIMERUPDATE_C 
2798   *                   @arg HRTIM_TIMERUPDATE_D 
2799   *                   @arg HRTIM_TIMERUPDATE_E 
2800   * @retval None
2801   * @note The 'software update' bits in the HRTIMx control register 2 register are
2802   *       automatically reset by hardware
2803   */
2804 void HRTIM_SoftwareUpdate(HRTIM_TypeDef * HRTIMx,
2805                                            uint32_t TimersToUpdate)
2806 {
2807   /* Check parameters */
2808   assert_param(IS_HRTIM_TIMERUPDATE(TimersToUpdate));
2809   
2810   /* Force timer(s) registers update */
2811   HRTIMx->HRTIM_COMMON.CR2 |= TimersToUpdate;
2812   
2813 }
2814
2815 /**
2816   * @brief  Triggers the reset of one or several timers
2817   * @param  HRTIMx: pointer to HRTIMx peripheral
2818   * @param  TimersToUpdate: timers concerned with the software counter reset
2819   *                   This parameter can be any combination of the following values:
2820   *                   @arg HRTIM_TIMER_MASTER 
2821   *                   @arg HRTIM_TIMER_A 
2822   *                   @arg HRTIM_TIMER_B 
2823   *                   @arg HRTIM_TIMER_C 
2824   *                   @arg HRTIM_TIMER_D 
2825   *                   @arg HRTIM_TIMER_E 
2826   * @retval None
2827   * @note The 'software reset' bits in the HRTIMx control register 2  are
2828   *       automatically reset by hardware
2829   */
2830 void HRTIM_SoftwareReset(HRTIM_TypeDef * HRTIMx,
2831                                           uint32_t TimersToReset)
2832 {
2833   /* Check parameters */
2834   assert_param(IS_HRTIM_TIMERRESET(TimersToReset));
2835   
2836   /* Force timer(s) registers update */
2837   HRTIMx->HRTIM_COMMON.CR2 |= TimersToReset;
2838  
2839 }
2840
2841 /**
2842   * @brief  Forces the timer output to its active or inactive state 
2843   * @param  HRTIMx: pointer to HRTIMx peripheral
2844   * @param  TimerIdx: Timer index
2845   *                   This parameter can be one of the following values:
2846   *                   @arg 0x0 to 0x4 for timers A to E 
2847   * @param  Output: Timer output
2848   *                    This parameter can be one of the following values:
2849   *                    @arg HRTIM_OUTPUT_TA1: Timer A - Output 1
2850   *                    @arg HRTIM_OUTPUT_TA2: Timer A - Output 2
2851   *                    @arg HRTIM_OUTPUT_TB1: Timer B - Output 1
2852   *                    @arg HRTIM_OUTPUT_TB2: Timer B - Output 2
2853   *                    @arg HRTIM_OUTPUT_TC1: Timer C - Output 1
2854   *                    @arg HRTIM_OUTPUT_TC2: Timer C - Output 2
2855   *                    @arg HRTIM_OUTPUT_TD1: Timer D - Output 1
2856   *                    @arg HRTIM_OUTPUT_TD2: Timer D - Output 2
2857   *                    @arg HRTIM_OUTPUT_TE1: Timer E - Output 1
2858   *                    @arg HRTIM_OUTPUT_TE2: Timer E - Output 2
2859   * @param OutputLevel: indicates whether the output is forced to its active or inactive state
2860   *                    This parameter can be one of the following values:
2861   *                    @arg HRTIM_OUTPUTLEVEL_ACTIVE: output is forced to its active state
2862   *                    @arg HRTIM_OUTPUTLEVEL_INACTIVE: output is forced to its inactive state
2863   * @retval None
2864   * @note The 'software set/reset trigger' bit in the output set/reset registers 
2865   *       is automatically reset by hardware
2866   */
2867 void HRTIM_WaveformSetOutputLevel(HRTIM_TypeDef * HRTIMx,
2868                                                    uint32_t TimerIdx,
2869                                                    uint32_t Output,
2870                                                    uint32_t OutputLevel)
2871 {
2872   /* Check parameters */
2873   assert_param(IS_HRTIM_TIMER_OUTPUT(TimerIdx, Output));
2874   assert_param(IS_HRTIM_OUTPUTLEVEL(OutputLevel));
2875
2876   /* Force timer output level */
2877   switch (Output)
2878   {
2879     case HRTIM_OUTPUT_TA1:
2880     case HRTIM_OUTPUT_TB1:
2881     case HRTIM_OUTPUT_TC1:
2882     case HRTIM_OUTPUT_TD1:
2883     case HRTIM_OUTPUT_TE1:
2884     {
2885       if (OutputLevel == HRTIM_OUTPUTLEVEL_ACTIVE)
2886       {
2887         /* Force output to its active state */
2888         HRTIMx->HRTIM_TIMERx[TimerIdx].SETx1R |= HRTIM_SET1R_SST;
2889       }
2890       else
2891       {
2892         /* Force output to its inactive state */
2893         HRTIMx->HRTIM_TIMERx[TimerIdx].RSTx1R |= HRTIM_RST1R_SRT;
2894       }
2895     }
2896     break;
2897     case HRTIM_OUTPUT_TA2:
2898     case HRTIM_OUTPUT_TB2:
2899     case HRTIM_OUTPUT_TC2:
2900     case HRTIM_OUTPUT_TD2:
2901     case HRTIM_OUTPUT_TE2:
2902     {
2903       if (OutputLevel == HRTIM_OUTPUTLEVEL_ACTIVE)
2904       {
2905         /* Force output to its active state */
2906         HRTIMx->HRTIM_TIMERx[TimerIdx].SETx2R |= HRTIM_SET2R_SST;
2907       }
2908       else
2909       {
2910         /* Force output to its inactive state */
2911         HRTIMx->HRTIM_TIMERx[TimerIdx].RSTx2R |= HRTIM_RST2R_SRT;
2912       }
2913     }
2914     break;
2915     default:
2916     break;
2917   } 
2918 }
2919
2920
2921 /**
2922   * @}
2923   */
2924
2925 /** @defgroup HRTIM_Group4 Peripheral State methods 
2926  *  @brief   Peripheral State functions 
2927  *
2928 @verbatim   
2929  ===============================================================================
2930                       ##### Peripheral State methods #####
2931  ===============================================================================  
2932     [..]
2933     This subsection permit to get in run-time the status of the peripheral 
2934     and the data flow.
2935
2936 @endverbatim
2937   * @{
2938   */
2939
2940 /**
2941   * @brief  Returns actual value of the capture register of the designated capture unit 
2942   * @param  HRTIMx: pointer to HRTIMx peripheral
2943   * @param  TimerIdx: Timer index
2944   *                   This parameter can be one of the following values:
2945   *                   @arg 0x0 to 0x4 for timers A to E 
2946   * @param  CaptureUnit: Capture unit to trig
2947   *                    This parameter can be one of the following values: 
2948   *                    @arg HRTIM_CAPTUREUNIT_1: Capture unit 1
2949   *                    @arg HRTIM_CAPTUREUNIT_2: Capture unit 2
2950   * @retval Captured value
2951   */
2952 uint32_t HRTIM_GetCapturedValue(HRTIM_TypeDef * HRTIMx,
2953                                     uint32_t TimerIdx,
2954                                     uint32_t CaptureUnit)
2955 {
2956   uint32_t captured_value = 0;
2957   
2958   /* Check parameters */
2959   assert_param(IS_HRTIM_TIMING_UNIT(TimerIdx));
2960   assert_param(IS_HRTIM_CAPTUREUNIT(CaptureUnit));
2961
2962   /* Read captured value */
2963   switch (CaptureUnit)
2964   {
2965     case HRTIM_CAPTUREUNIT_1:
2966     {
2967       captured_value = HRTIMx->HRTIM_TIMERx[TimerIdx].CPT1xR;
2968     }
2969     break;
2970     case HRTIM_CAPTUREUNIT_2:
2971     {
2972       captured_value = HRTIMx->HRTIM_TIMERx[TimerIdx].CPT2xR;
2973     }
2974     break;
2975     default:
2976     break;
2977   }
2978   
2979   return captured_value; 
2980 }
2981
2982 /**
2983   * @brief  Returns actual level (active or inactive) of the designated output 
2984   * @param  HRTIMx: pointer to HRTIMx peripheral
2985   * @param  TimerIdx: Timer index
2986   *                   This parameter can be one of the following values:
2987   *                   @arg 0x0 to 0x4 for timers A to E 
2988   * @param  Output: Timer output
2989   *                    This parameter can be one of the following values:
2990   *                    @arg HRTIM_OUTPUT_TA1: Timer A - Output 1
2991   *                    @arg HRTIM_OUTPUT_TA2: Timer A - Output 2
2992   *                    @arg HRTIM_OUTPUT_TB1: Timer B - Output 1
2993   *                    @arg HRTIM_OUTPUT_TB2: Timer B - Output 2
2994   *                    @arg HRTIM_OUTPUT_TC1: Timer C - Output 1
2995   *                    @arg HRTIM_OUTPUT_TC2: Timer C - Output 2
2996   *                    @arg HRTIM_OUTPUT_TD1: Timer D - Output 1
2997   *                    @arg HRTIM_OUTPUT_TD2: Timer D - Output 2
2998   *                    @arg HRTIM_OUTPUT_TE1: Timer E - Output 1
2999   *                    @arg HRTIM_OUTPUT_TE2: Timer E - Output 2
3000   * @retval Output level
3001   * @note Returned output level is taken before the output stage (chopper, 
3002   *        polarity).
3003   */
3004 uint32_t HRTIM_WaveformGetOutputLevel(HRTIM_TypeDef * HRTIMx,
3005                                           uint32_t TimerIdx,
3006                                           uint32_t Output)
3007 {
3008   uint32_t output_level = HRTIM_OUTPUTLEVEL_INACTIVE;
3009   
3010   /* Check parameters */
3011   assert_param(IS_HRTIM_TIMER_OUTPUT(TimerIdx, Output));
3012   
3013   /* Read the output level */
3014   switch (Output)
3015   {
3016     case HRTIM_OUTPUT_TA1:
3017     case HRTIM_OUTPUT_TB1:
3018     case HRTIM_OUTPUT_TC1:
3019     case HRTIM_OUTPUT_TD1:
3020     case HRTIM_OUTPUT_TE1:
3021     {
3022       if ((HRTIMx->HRTIM_TIMERx[TimerIdx].TIMxISR & HRTIM_TIMISR_O1CPY) != RESET)
3023       {
3024         output_level = HRTIM_OUTPUTLEVEL_ACTIVE;
3025       }
3026       else
3027       {
3028         output_level = HRTIM_OUTPUTLEVEL_INACTIVE;
3029       }
3030     }
3031     break;
3032     case HRTIM_OUTPUT_TA2:
3033     case HRTIM_OUTPUT_TB2:
3034     case HRTIM_OUTPUT_TC2:
3035     case HRTIM_OUTPUT_TD2:
3036     case HRTIM_OUTPUT_TE2:
3037     {
3038       if ((HRTIMx->HRTIM_TIMERx[TimerIdx].TIMxISR & HRTIM_TIMISR_O2CPY) != RESET)
3039       {
3040         output_level = HRTIM_OUTPUTLEVEL_ACTIVE;
3041       }
3042       else
3043       {
3044         output_level = HRTIM_OUTPUTLEVEL_INACTIVE;
3045       }
3046     }
3047     break;
3048     default:
3049     break;
3050   }
3051   
3052   return output_level; 
3053 }
3054
3055 /**
3056   * @brief  Returns actual state (RUN, IDLE, FAULT) of the designated output 
3057   * @param  HRTIMx: pointer to HRTIMx peripheral
3058   * @param  TimerIdx: Timer index
3059   *                   This parameter can be one of the following values:
3060   *                   @arg 0x0 to 0x4 for timers A to E 
3061   * @param  Output: Timer output
3062   *                    This parameter can be one of the following values:
3063   *                    @arg HRTIM_OUTPUT_TA1: Timer A - Output 1
3064   *                    @arg HRTIM_OUTPUT_TA2: Timer A - Output 2
3065   *                    @arg HRTIM_OUTPUT_TB1: Timer B - Output 1
3066   *                    @arg HRTIM_OUTPUT_TB2: Timer B - Output 2
3067   *                    @arg HRTIM_OUTPUT_TC1: Timer C - Output 1
3068   *                    @arg HRTIM_OUTPUT_TC2: Timer C - Output 2
3069   *                    @arg HRTIM_OUTPUT_TD1: Timer D - Output 1
3070   *                    @arg HRTIM_OUTPUT_TD2: Timer D - Output 2
3071   *                    @arg HRTIM_OUTPUT_TE1: Timer E - Output 1
3072   *                    @arg HRTIM_OUTPUT_TE2: Timer E - Output 2
3073   * @retval Output state
3074   */
3075 uint32_t HRTIM_WaveformGetOutputState(HRTIM_TypeDef * HRTIMx,
3076                                           uint32_t TimerIdx,
3077                                           uint32_t Output)
3078 {
3079   uint32_t output_bit = 0;
3080   uint32_t output_state = HRTIM_OUTPUTSTATE_IDLE;
3081   
3082   /* Check parameters */
3083   assert_param(IS_HRTIM_TIMER_OUTPUT(TimerIdx, Output));
3084   
3085   /* Set output state according to output control status and output disable status */
3086   switch (Output)
3087   {
3088     case HRTIM_OUTPUT_TA1:
3089     {
3090       output_bit = HRTIM_OENR_TA1OEN;
3091     }
3092     break;
3093     case HRTIM_OUTPUT_TA2:
3094     {
3095       output_bit = HRTIM_OENR_TA2OEN;
3096     }
3097     break;
3098     case HRTIM_OUTPUT_TB1:
3099     {
3100       output_bit = HRTIM_OENR_TB1OEN;
3101     }
3102     break;
3103     case HRTIM_OUTPUT_TB2:
3104     {
3105       output_bit = HRTIM_OENR_TB2OEN;
3106     }
3107     break;
3108     case HRTIM_OUTPUT_TC1:
3109     {
3110       output_bit = HRTIM_OENR_TC1OEN;
3111     }
3112     break;
3113     case HRTIM_OUTPUT_TC2:
3114     {
3115       output_bit = HRTIM_OENR_TC2OEN;
3116     }
3117     break;
3118     case HRTIM_OUTPUT_TD1:
3119     {
3120       output_bit = HRTIM_OENR_TD1OEN;
3121     }
3122     break;
3123     case HRTIM_OUTPUT_TD2:
3124     {
3125       output_bit = HRTIM_OENR_TD2OEN;
3126     }
3127     break;
3128     case HRTIM_OUTPUT_TE1:
3129     {
3130       output_bit = HRTIM_OENR_TE1OEN;
3131     }
3132     break;
3133     case HRTIM_OUTPUT_TE2:
3134     {
3135       output_bit = HRTIM_OENR_TE2OEN;
3136     }
3137     break;
3138     default:
3139     break;
3140   }
3141   
3142   if ((HRTIMx->HRTIM_COMMON.OENR & output_bit) != RESET)
3143   {
3144     /* Output is enabled: output in RUN state (whatever ouput disable status is)*/
3145     output_state = HRTIM_OUTPUTSTATE_RUN;
3146   }
3147   else
3148   {
3149     if ((HRTIMx->HRTIM_COMMON.ODSR & output_bit) != RESET)
3150     {
3151     /* Output is disabled: output in FAULT state */
3152       output_state = HRTIM_OUTPUTSTATE_FAULT;
3153     }
3154     else
3155     {
3156       /* Output is disabled: output in IDLE state */
3157       output_state = HRTIM_OUTPUTSTATE_IDLE;
3158     }
3159   }
3160   
3161   return(output_state);  
3162 }
3163
3164 /**
3165   * @brief  Returns the level (active or inactive) of the designated output 
3166   *         when the delayed protection was triggered 
3167   * @param  HRTIMx: pointer to HRTIMx peripheral
3168   * @param  TimerIdx: Timer index
3169   *                   This parameter can be one of the following values:
3170   *                   @arg 0x0 to 0x4 for timers A to E 
3171   * @param  Output: Timer output
3172   *                    This parameter can be one of the following values:
3173   *                    @arg HRTIM_OUTPUT_TA1: Timer A - Output 1
3174   *                    @arg HRTIM_OUTPUT_TA2: Timer A - Output 2
3175   *                    @arg HRTIM_OUTPUT_TB1: Timer B - Output 1
3176   *                    @arg HRTIM_OUTPUT_TB2: Timer B - Output 2
3177   *                    @arg HRTIM_OUTPUT_TC1: Timer C - Output 1
3178   *                    @arg HRTIM_OUTPUT_TC2: Timer C - Output 2
3179   *                    @arg HRTIM_OUTPUT_TD1: Timer D - Output 1
3180   *                    @arg HRTIM_OUTPUT_TD2: Timer D - Output 2
3181   *                    @arg HRTIM_OUTPUT_TD1: Timer E - Output 1
3182   *                    @arg HRTIM_OUTPUT_TD2: Timer E - Output 2
3183   * @retval Delayed protection status 
3184   */
3185 uint32_t HRTIM_GetDelayedProtectionStatus(HRTIM_TypeDef * HRTIMx,
3186                                               uint32_t TimerIdx,
3187                                               uint32_t Output)
3188 {
3189   uint32_t delayed_protection_status = HRTIM_OUTPUTLEVEL_INACTIVE;
3190   
3191   /* Check parameters */
3192   assert_param(IS_HRTIM_TIMER_OUTPUT(TimerIdx, Output));
3193
3194   /* Read the delayed protection status */
3195   switch (Output)
3196   {
3197     case HRTIM_OUTPUT_TA1:
3198     case HRTIM_OUTPUT_TB1:
3199     case HRTIM_OUTPUT_TC1:
3200     case HRTIM_OUTPUT_TD1:
3201     case HRTIM_OUTPUT_TE1:
3202     {
3203       if ((HRTIMx->HRTIM_TIMERx[TimerIdx].TIMxISR & HRTIM_TIMISR_O1STAT) != RESET)
3204       {
3205         /* Output 1 was active when the delayed idle protection was triggered */
3206         delayed_protection_status = HRTIM_OUTPUTLEVEL_ACTIVE;
3207       }
3208       else
3209       {
3210         /* Output 1 was inactive when the delayed idle protection was triggered */
3211         delayed_protection_status = HRTIM_OUTPUTLEVEL_INACTIVE;
3212       }
3213     }
3214     break;
3215     case HRTIM_OUTPUT_TA2:
3216     case HRTIM_OUTPUT_TB2:
3217     case HRTIM_OUTPUT_TC2:
3218     case HRTIM_OUTPUT_TD2:
3219     case HRTIM_OUTPUT_TE2:
3220     {
3221       if ((HRTIMx->HRTIM_TIMERx[TimerIdx].TIMxISR & HRTIM_TIMISR_O2STAT) != RESET)
3222       {
3223         /* Output 2 was active when the delayed idle protection was triggered */
3224         delayed_protection_status = HRTIM_OUTPUTLEVEL_ACTIVE;
3225       }
3226       else
3227       {
3228         /* Output 2 was inactive when the delayed idle protection was triggered */
3229         delayed_protection_status = HRTIM_OUTPUTLEVEL_INACTIVE;
3230       }
3231     }
3232     break;
3233     default:
3234     break;
3235   }
3236   
3237   return delayed_protection_status;
3238 }
3239
3240 /**
3241   * @brief  Returns the actual status (active or inactive) of the burst mode controller 
3242   * @param  HRTIMx: pointer to HRTIMx peripheral
3243   * @retval Burst mode controller status 
3244   */
3245 uint32_t HRTIM_GetBurstStatus(HRTIM_TypeDef * HRTIMx)
3246 {
3247   uint32_t burst_mode_status;
3248
3249   /* Read burst mode status */
3250   burst_mode_status = (HRTIMx->HRTIM_COMMON.BMCR & HRTIM_BMCR_BMSTAT);
3251   
3252   return burst_mode_status; 
3253 }
3254
3255 /**
3256   * @brief  Indicates on which output the signal is currently active (when the
3257   *         push pull mode is enabled)
3258   * @param  HRTIMx: pointer to HRTIMx peripheral
3259   * @param  TimerIdx: Timer index
3260   *                   This parameter can be one of the following values:
3261   *                   @arg 0x0 to 0x4 for timers A to E 
3262   * @retval Burst mode controller status 
3263   */
3264 uint32_t HRTIM_GetCurrentPushPullStatus(HRTIM_TypeDef * HRTIMx,
3265                                             uint32_t TimerIdx)
3266 {
3267   uint32_t current_pushpull_status;
3268
3269    /* Check the parameters */
3270   assert_param(IS_HRTIM_TIMING_UNIT(TimerIdx));
3271
3272   /* Read current push pull status */
3273   current_pushpull_status = (HRTIMx->HRTIM_TIMERx[TimerIdx].TIMxISR & HRTIM_TIMISR_CPPSTAT);
3274   
3275   return current_pushpull_status; 
3276 }
3277
3278
3279 /**
3280   * @brief  Indicates on which output the signal was applied, in push-pull mode
3281             balanced fault mode or delayed idle mode, when the protection was triggered
3282   * @param  HRTIMx: pointer to HRTIMx peripheral
3283   * @param  TimerIdx: Timer index
3284   *                   This parameter can be one of the following values:
3285   *                   @arg 0x0 to 0x4 for timers A to E 
3286   * @retval Idle Push Pull Status 
3287   */
3288 uint32_t HRTIM_GetIdlePushPullStatus(HRTIM_TypeDef * HRTIMx,
3289                                          uint32_t TimerIdx)
3290 {
3291   uint32_t idle_pushpull_status;
3292
3293    /* Check the parameters */
3294   assert_param(IS_HRTIM_TIMING_UNIT(TimerIdx));
3295
3296   /* Read current push pull status */
3297   idle_pushpull_status = (HRTIMx->HRTIM_TIMERx[TimerIdx].TIMxISR & HRTIM_TIMISR_IPPSTAT);
3298   
3299   return idle_pushpull_status; 
3300 }
3301
3302 /**
3303   * @brief  Configures the master timer time base
3304   * @param  HRTIMx: pointer to HRTIMx peripheral
3305   * @retval None
3306   */
3307 void  HRTIM_MasterBase_Config(HRTIM_TypeDef * HRTIMx, HRTIM_BaseInitTypeDef* HRTIM_BaseInitStruct)
3308 {  
3309   /* Set the prescaler ratio */
3310   HRTIMx->HRTIM_MASTER.MCR &= (uint32_t) ~(HRTIM_MCR_CK_PSC);
3311   HRTIMx->HRTIM_MASTER.MCR  |= (uint32_t)HRTIM_BaseInitStruct->PrescalerRatio;
3312   
3313   /* Set the operating mode */
3314   HRTIMx->HRTIM_MASTER.MCR  &= (uint32_t) ~(HRTIM_MCR_CONT | HRTIM_MCR_RETRIG);
3315   HRTIMx->HRTIM_MASTER.MCR  |= (uint32_t)HRTIM_BaseInitStruct->Mode;
3316   
3317   /* Update the HRTIMx registers */
3318   HRTIMx->HRTIM_MASTER.MPER = HRTIM_BaseInitStruct->Period;
3319   HRTIMx->HRTIM_MASTER.MREP = HRTIM_BaseInitStruct->RepetitionCounter;
3320 }
3321
3322 /**
3323   * @brief  Configures timing unit (timer A to timer E) time base
3324   * @param  HRTIMx: pointer to HRTIMx peripheral
3325   * @param  TimerIdx: Timer index
3326   * @retval None
3327   */
3328 void HRTIM_TimingUnitBase_Config(HRTIM_TypeDef * HRTIMx, uint32_t TimerIdx, HRTIM_BaseInitTypeDef* HRTIM_BaseInitStruct)
3329 {   
3330   /* Set the prescaler ratio */
3331   HRTIMx->HRTIM_TIMERx[TimerIdx].TIMxCR &= (uint32_t) ~(HRTIM_TIMCR_CK_PSC);
3332   HRTIMx->HRTIM_TIMERx[TimerIdx].TIMxCR |= (uint32_t)HRTIM_BaseInitStruct->PrescalerRatio;
3333
3334   /* Set the operating mode */
3335   HRTIMx->HRTIM_TIMERx[TimerIdx].TIMxCR &= (uint32_t) ~(HRTIM_TIMCR_CONT | HRTIM_TIMCR_RETRIG);
3336   HRTIMx->HRTIM_TIMERx[TimerIdx].TIMxCR |= (uint32_t)HRTIM_BaseInitStruct->Mode;
3337   
3338   /* Update the HRTIMx registers */
3339   HRTIMx->HRTIM_TIMERx[TimerIdx].PERxR = HRTIM_BaseInitStruct->Period;
3340   HRTIMx->HRTIM_TIMERx[TimerIdx].REPxR = HRTIM_BaseInitStruct->RepetitionCounter;
3341 }
3342
3343 /**
3344   * @brief  Configures the master timer in waveform mode
3345   * @param  HRTIMx: pointer to HRTIMx peripheral
3346   * @param  TimerIdx: Timer index
3347   * @param  pTimerInit: pointer to the timer initialization data structure
3348   * @retval None
3349   */
3350 void  HRTIM_MasterWaveform_Config(HRTIM_TypeDef * HRTIMx, 
3351                                 HRTIM_TimerInitTypeDef * pTimerInit)
3352 {
3353   uint32_t HRTIM_mcr;
3354   uint32_t HRTIM_bmcr;
3355   
3356   /* Configure master timer */
3357   HRTIM_mcr = HRTIMx->HRTIM_MASTER.MCR;
3358   HRTIM_bmcr = HRTIMx->HRTIM_COMMON.BMCR;
3359   
3360   /* Enable/Disable the half mode */
3361   HRTIM_mcr &= ~(HRTIM_MCR_HALF);
3362   HRTIM_mcr |= pTimerInit->HalfModeEnable;
3363   
3364   /* Enable/Disable the timer start upon synchronization event reception */
3365   HRTIM_mcr &= ~(HRTIM_MCR_SYNCSTRTM);
3366   HRTIM_mcr |= pTimerInit->StartOnSync;
3367  
3368   /* Enable/Disable the timer reset upon synchronization event reception */
3369   HRTIM_mcr &= ~(HRTIM_MCR_SYNCRSTM);
3370   HRTIM_mcr |= pTimerInit->ResetOnSync;
3371   
3372   /* Enable/Disable the DAC synchronization event generation */
3373   HRTIM_mcr &= ~(HRTIM_MCR_DACSYNC);
3374   HRTIM_mcr |= pTimerInit->DACSynchro;
3375   
3376   /* Enable/Disable preload mechanism for timer registers */
3377   HRTIM_mcr &= ~(HRTIM_MCR_PREEN);
3378   HRTIM_mcr |= pTimerInit->PreloadEnable;
3379   
3380   /* Master timer registers update handling */
3381   HRTIM_mcr &= ~(HRTIM_MCR_BRSTDMA);
3382   HRTIM_mcr |= (pTimerInit->UpdateGating << 2);
3383   
3384   /* Enable/Disable registers update on repetition */
3385   HRTIM_mcr &= ~(HRTIM_MCR_MREPU);
3386   HRTIM_mcr |= pTimerInit->RepetitionUpdate;
3387   
3388   /* Set the timer burst mode */
3389   HRTIM_bmcr &= ~(HRTIM_BMCR_MTBM);
3390   HRTIM_bmcr |= pTimerInit->BurstMode;
3391
3392   /* Update the HRTIMx registers */
3393   HRTIMx->HRTIM_MASTER.MCR  = HRTIM_mcr;
3394   HRTIMx->HRTIM_COMMON.BMCR = HRTIM_bmcr;
3395   
3396 }
3397
3398 /**
3399   * @brief  Configures timing unit (timer A to timer E) in waveform mode 
3400   * @param  HRTIMx: pointer to HRTIMx peripheral
3401   * @param  TimerIdx: Timer index
3402   * @param  pTimerInit: pointer to the timer initialization data structure
3403   * @retval None
3404   */
3405 void HRTIM_TimingUnitWaveform_Config(HRTIM_TypeDef * HRTIMx, 
3406                                     uint32_t TimerIdx, 
3407                                     HRTIM_TimerInitTypeDef * pTimerInit)
3408 {
3409   uint32_t HRTIM_timcr;
3410   uint32_t HRTIM_bmcr;
3411   
3412   /* Configure timing unit */
3413   HRTIM_timcr = HRTIMx->HRTIM_TIMERx[TimerIdx].TIMxCR;
3414   HRTIM_bmcr = HRTIMx->HRTIM_COMMON.BMCR;
3415   
3416   /* Enable/Disable the half mode */
3417   HRTIM_timcr &= ~(HRTIM_TIMCR_HALF);
3418   HRTIM_timcr |= pTimerInit->HalfModeEnable;
3419   
3420   /* Enable/Disable the timer start upon synchronization event reception */
3421   HRTIM_timcr &= ~(HRTIM_TIMCR_SYNCSTRT);
3422   HRTIM_timcr |= pTimerInit->StartOnSync;
3423  
3424   /* Enable/Disable the timer reset upon synchronization event reception */
3425   HRTIM_timcr &= ~(HRTIM_TIMCR_SYNCRST);
3426   HRTIM_timcr |= pTimerInit->ResetOnSync;
3427   
3428   /* Enable/Disable the DAC synchronization event generation */
3429   HRTIM_timcr &= ~(HRTIM_TIMCR_DACSYNC);
3430   HRTIM_timcr |= pTimerInit->DACSynchro;
3431   
3432   /* Enable/Disable preload mechanism for timer registers */
3433   HRTIM_timcr &= ~(HRTIM_TIMCR_PREEN);
3434   HRTIM_timcr |= pTimerInit->PreloadEnable;
3435   
3436   /* Timing unit registers update handling */
3437   HRTIM_timcr &= ~(HRTIM_TIMCR_UPDGAT);
3438   HRTIM_timcr |= pTimerInit->UpdateGating;
3439   
3440   /* Enable/Disable registers update on repetition */
3441   HRTIM_timcr &= ~(HRTIM_TIMCR_TREPU);
3442   if (pTimerInit->RepetitionUpdate == HRTIM_UPDATEONREPETITION_ENABLED)
3443   {
3444     HRTIM_timcr |= HRTIM_TIMCR_TREPU;
3445   }
3446
3447   /* Set the timer burst mode */
3448   switch (TimerIdx)
3449   {
3450     case HRTIM_TIMERINDEX_TIMER_A:
3451     {
3452       HRTIM_bmcr &= ~(HRTIM_BMCR_TABM);
3453       HRTIM_bmcr |= ( pTimerInit->BurstMode << 1);
3454     }
3455     break;
3456     case HRTIM_TIMERINDEX_TIMER_B:
3457     {
3458       HRTIM_bmcr &= ~(HRTIM_BMCR_TBBM);
3459       HRTIM_bmcr |= ( pTimerInit->BurstMode << 2);
3460     }
3461     break;
3462     case HRTIM_TIMERINDEX_TIMER_C:
3463     {
3464       HRTIM_bmcr &= ~(HRTIM_BMCR_TCBM);
3465       HRTIM_bmcr |= ( pTimerInit->BurstMode << 3);
3466     }
3467     break;
3468     case HRTIM_TIMERINDEX_TIMER_D:
3469     {
3470       HRTIM_bmcr &= ~(HRTIM_BMCR_TDBM);
3471       HRTIM_bmcr |= ( pTimerInit->BurstMode << 4);
3472     }
3473     break;
3474     case HRTIM_TIMERINDEX_TIMER_E:
3475     {
3476       HRTIM_bmcr &= ~(HRTIM_BMCR_TEBM);
3477       HRTIM_bmcr |= ( pTimerInit->BurstMode << 5);
3478     }
3479     break;
3480     default:
3481     break;
3482   }
3483   
3484   /* Update the HRTIMx registers */
3485   HRTIMx->HRTIM_TIMERx[TimerIdx].TIMxCR = HRTIM_timcr;
3486   HRTIMx->HRTIM_COMMON.BMCR = HRTIM_bmcr;
3487 }
3488
3489 /**
3490   * @brief  Configures a compare unit 
3491   * @param  HRTIMx: pointer to HRTIMx peripheral
3492   * @param  TimerIdx: Timer index
3493   * @param  CompareUnit: Compare unit identifier
3494   * @param  pCompareCfg: pointer to the compare unit configuration data structure
3495   * @retval None
3496   */
3497 void  HRTIM_CompareUnitConfig(HRTIM_TypeDef * HRTIMx,
3498                               uint32_t TimerIdx,
3499                               uint32_t CompareUnit,
3500                               HRTIM_CompareCfgTypeDef * pCompareCfg)
3501 {
3502   if (TimerIdx == HRTIM_TIMERINDEX_MASTER)
3503   {
3504     /* Configure the compare unit of the master timer */
3505     switch (CompareUnit)
3506     {
3507       case HRTIM_COMPAREUNIT_1:
3508       {
3509         HRTIMx->HRTIM_MASTER.MCMP1R = pCompareCfg->CompareValue;
3510       }
3511       break;
3512       case HRTIM_COMPAREUNIT_2:
3513       {
3514         HRTIMx->HRTIM_MASTER.MCMP2R = pCompareCfg->CompareValue;
3515       }
3516       break;
3517       case HRTIM_COMPAREUNIT_3:
3518       {
3519         HRTIMx->HRTIM_MASTER.MCMP3R = pCompareCfg->CompareValue;
3520       }
3521       break;
3522       case HRTIM_COMPAREUNIT_4:
3523       {
3524         HRTIMx->HRTIM_MASTER.MCMP4R = pCompareCfg->CompareValue;
3525       }
3526       break;
3527       default:
3528       break;
3529     }
3530   }
3531   else
3532   {
3533     /* Configure the compare unit of the timing unit */
3534     switch (CompareUnit)
3535     {
3536       case HRTIM_COMPAREUNIT_1:
3537       {
3538         HRTIMx->HRTIM_TIMERx[TimerIdx].CMP1xR = pCompareCfg->CompareValue;
3539       }
3540       break;
3541       case HRTIM_COMPAREUNIT_2:
3542       {
3543         HRTIMx->HRTIM_TIMERx[TimerIdx].CMP2xR = pCompareCfg->CompareValue;
3544       }
3545       break;
3546       case HRTIM_COMPAREUNIT_3:
3547       {
3548         HRTIMx->HRTIM_TIMERx[TimerIdx].CMP3xR = pCompareCfg->CompareValue;
3549       }
3550       break;
3551       case HRTIM_COMPAREUNIT_4:
3552       {
3553         HRTIMx->HRTIM_TIMERx[TimerIdx].CMP4xR = pCompareCfg->CompareValue;
3554       }
3555       break;
3556       default:
3557       break;
3558     }
3559   }
3560 }
3561
3562 /**
3563   * @brief  Configures a capture unit 
3564   * @param  HRTIMx: pointer to HRTIMx peripheral
3565   * @param  TimerIdx: Timer index
3566   * @param  CaptureUnit: Capture unit identifier
3567   * @param  pCaptureCfg: pointer to the compare unit configuration data structure
3568   * @retval None
3569   */
3570 void HRTIM_CaptureUnitConfig(HRTIM_TypeDef * HRTIMx,
3571                              uint32_t TimerIdx,
3572                              uint32_t CaptureUnit,
3573                              uint32_t Event)
3574 {
3575   uint32_t CaptureTrigger = HRTIM_CAPTURETRIGGER_EEV_1;
3576   
3577   switch (Event)
3578   {
3579     case HRTIM_EVENT_1:
3580     {
3581       CaptureTrigger = HRTIM_CAPTURETRIGGER_EEV_1;
3582     }
3583     break;
3584     case HRTIM_EVENT_2:
3585     {
3586       CaptureTrigger = HRTIM_CAPTURETRIGGER_EEV_2;
3587     }
3588     break;
3589     case HRTIM_EVENT_3:
3590     {
3591       CaptureTrigger = HRTIM_CAPTURETRIGGER_EEV_3;
3592     }
3593     break;
3594     case HRTIM_EVENT_4:
3595     {
3596       CaptureTrigger = HRTIM_CAPTURETRIGGER_EEV_4;
3597     }
3598     break;
3599     case HRTIM_EVENT_5:
3600     {
3601       CaptureTrigger = HRTIM_CAPTURETRIGGER_EEV_5;
3602     }
3603     break;
3604     case HRTIM_EVENT_6:
3605     {
3606       CaptureTrigger = HRTIM_CAPTURETRIGGER_EEV_6;
3607     }
3608     break;
3609     case HRTIM_EVENT_7:
3610     {
3611       CaptureTrigger = HRTIM_CAPTURETRIGGER_EEV_7;
3612     }
3613     break;
3614     case HRTIM_EVENT_8:
3615     {
3616       CaptureTrigger = HRTIM_CAPTURETRIGGER_EEV_8;
3617     }
3618     break;
3619     case HRTIM_EVENT_9:
3620     {
3621       CaptureTrigger = HRTIM_CAPTURETRIGGER_EEV_9;
3622     }
3623     break;
3624     case HRTIM_EVENT_10:
3625     {
3626       CaptureTrigger = HRTIM_CAPTURETRIGGER_EEV_10;
3627     }
3628     break;
3629     default:
3630     break;  
3631     
3632   }  
3633   switch (CaptureUnit)
3634   {
3635     case HRTIM_CAPTUREUNIT_1:
3636     {
3637       HRTIMx->HRTIM_TIMERx[TimerIdx].CPT1xCR = CaptureTrigger;
3638     }
3639     break;
3640     case HRTIM_CAPTUREUNIT_2:
3641     {
3642       HRTIMx->HRTIM_TIMERx[TimerIdx].CPT2xCR = CaptureTrigger;
3643     }
3644     break;
3645     default:
3646     break;  
3647   }
3648 }
3649
3650 /**
3651   * @brief  Configures the output of a timing unit 
3652   * @param  HRTIMx: pointer to HRTIMx peripheral
3653   * @param  TimerIdx: Timer index
3654   * @param  Output: timing unit output identifier
3655   * @param  pOutputCfg: pointer to the output configuration data structure
3656   * @retval None
3657   */
3658 void  HRTIM_OutputConfig(HRTIM_TypeDef * HRTIMx,
3659                          uint32_t TimerIdx,
3660                          uint32_t Output,
3661                          HRTIM_OutputCfgTypeDef * pOutputCfg)
3662 {
3663   uint32_t HRTIM_outr;
3664   uint32_t shift = 0;
3665   
3666   HRTIM_outr = HRTIMx->HRTIM_TIMERx[TimerIdx].OUTxR;
3667   
3668   switch (Output)
3669   {
3670     case HRTIM_OUTPUT_TA1:
3671     case HRTIM_OUTPUT_TB1:
3672     case HRTIM_OUTPUT_TC1:
3673     case HRTIM_OUTPUT_TD1:
3674     case HRTIM_OUTPUT_TE1:
3675     {
3676       /* Set the output set/reset crossbar */
3677       HRTIMx->HRTIM_TIMERx[TimerIdx].SETx1R = pOutputCfg->SetSource;
3678       HRTIMx->HRTIM_TIMERx[TimerIdx].RSTx1R = pOutputCfg->ResetSource;
3679       
3680       shift = 0;
3681     }
3682     break;
3683     case HRTIM_OUTPUT_TA2:
3684     case HRTIM_OUTPUT_TB2:
3685     case HRTIM_OUTPUT_TC2:
3686     case HRTIM_OUTPUT_TD2:
3687     case HRTIM_OUTPUT_TE2:
3688     {
3689       /* Set the output set/reset crossbar */
3690       HRTIMx->HRTIM_TIMERx[TimerIdx].SETx2R = pOutputCfg->SetSource;
3691       HRTIMx->HRTIM_TIMERx[TimerIdx].RSTx2R = pOutputCfg->ResetSource;
3692
3693       shift = 16;
3694     }
3695     break;
3696     default:
3697     break;
3698   }
3699   
3700   /* Clear output config */
3701   HRTIM_outr &= ~((HRTIM_OUTR_POL1 |
3702                    HRTIM_OUTR_IDLM1 |
3703                    HRTIM_OUTR_IDLES1|
3704                    HRTIM_OUTR_FAULT1|
3705                    HRTIM_OUTR_CHP1 |
3706                    HRTIM_OUTR_DIDL1)  << shift);
3707   
3708   /* Set the polarity */
3709   HRTIM_outr |= (pOutputCfg->Polarity << shift);
3710   
3711   /* Set the IDLE mode */
3712   HRTIM_outr |= (pOutputCfg->IdleMode << shift);
3713   
3714   /* Set the IDLE state */
3715   HRTIM_outr |= (pOutputCfg->IdleState << shift);
3716   
3717   /* Set the FAULT state */
3718   HRTIM_outr |= (pOutputCfg->FaultState << shift);
3719   
3720   /* Set the chopper mode */
3721   HRTIM_outr |= (pOutputCfg->ChopperModeEnable << shift);
3722
3723   /* Set the burst mode entry mode */
3724   HRTIM_outr |= (pOutputCfg->BurstModeEntryDelayed << shift);
3725   
3726   /* Update HRTIMx register */
3727   HRTIMx->HRTIM_TIMERx[TimerIdx].OUTxR = HRTIM_outr;
3728 }
3729
3730 /**
3731   * @brief  Configures an external event channel 
3732   * @param  HRTIMx: pointer to HRTIMx peripheral
3733   * @param  Event: Event channel identifier
3734   * @param  pEventCfg: pointer to the event channel configuration data structure
3735   * @retval None
3736   */
3737 static void HRTIM_ExternalEventConfig(HRTIM_TypeDef * HRTIMx,
3738                               uint32_t Event,
3739                               HRTIM_EventCfgTypeDef *pEventCfg)
3740 {
3741   uint32_t hrtim_eecr1;
3742   uint32_t hrtim_eecr2;
3743   uint32_t hrtim_eecr3;
3744
3745   /* Configure external event channel */
3746   hrtim_eecr1 = HRTIMx->HRTIM_COMMON.EECR1;
3747   hrtim_eecr2 = HRTIMx->HRTIM_COMMON.EECR2;
3748   hrtim_eecr3 = HRTIMx->HRTIM_COMMON.EECR3;
3749   
3750   switch (Event)
3751   {
3752     case HRTIM_EVENT_1:
3753     {
3754       hrtim_eecr1 &= ~(HRTIM_EECR1_EE1SRC | HRTIM_EECR1_EE1POL | HRTIM_EECR1_EE1SNS | HRTIM_EECR1_EE1FAST);
3755       hrtim_eecr1 |= pEventCfg->Source;
3756       hrtim_eecr1 |= pEventCfg->Polarity;
3757       hrtim_eecr1 |= pEventCfg->Sensitivity;
3758       /* Update the HRTIM registers (all bit fields but EE1FAST bit) */
3759       HRTIMx->HRTIM_COMMON.EECR1 = hrtim_eecr1;
3760       /* Update the HRTIM registers (EE1FAST bit) */
3761       hrtim_eecr1 |= pEventCfg->FastMode;
3762       HRTIMx->HRTIM_COMMON.EECR1 = hrtim_eecr1;
3763     }
3764     break;
3765     case HRTIM_EVENT_2:
3766     {
3767       hrtim_eecr1 &= ~(HRTIM_EECR1_EE2SRC | HRTIM_EECR1_EE2POL | HRTIM_EECR1_EE2SNS | HRTIM_EECR1_EE2FAST);
3768       hrtim_eecr1 |= (pEventCfg->Source << 6);
3769       hrtim_eecr1 |= (pEventCfg->Polarity << 6);
3770       hrtim_eecr1 |= (pEventCfg->Sensitivity << 6);
3771       /* Update the HRTIM registers (all bit fields but EE2FAST bit) */
3772       HRTIMx->HRTIM_COMMON.EECR1 = hrtim_eecr1;
3773       /* Update the HRTIM registers (EE2FAST bit) */
3774       hrtim_eecr1 |= (pEventCfg->FastMode << 6);
3775       HRTIMx->HRTIM_COMMON.EECR1 = hrtim_eecr1;
3776     }
3777     break;
3778     case HRTIM_EVENT_3:
3779     {
3780       hrtim_eecr1 &= ~(HRTIM_EECR1_EE3SRC | HRTIM_EECR1_EE3POL | HRTIM_EECR1_EE3SNS | HRTIM_EECR1_EE3FAST);
3781       hrtim_eecr1 |= (pEventCfg->Source << 12);
3782       hrtim_eecr1 |= (pEventCfg->Polarity << 12);
3783       hrtim_eecr1 |= (pEventCfg->Sensitivity << 12);
3784       /* Update the HRTIM registers (all bit fields but EE3FAST bit) */
3785       HRTIMx->HRTIM_COMMON.EECR1 = hrtim_eecr1;
3786       /* Update the HRTIM registers (EE3FAST bit) */
3787       hrtim_eecr1 |= (pEventCfg->FastMode << 12);
3788       HRTIMx->HRTIM_COMMON.EECR1 = hrtim_eecr1;
3789     }
3790     break;
3791     case HRTIM_EVENT_4:
3792     {
3793       hrtim_eecr1 &= ~(HRTIM_EECR1_EE4SRC | HRTIM_EECR1_EE4POL | HRTIM_EECR1_EE4SNS | HRTIM_EECR1_EE4FAST);
3794       hrtim_eecr1 |= (pEventCfg->Source << 18);
3795       hrtim_eecr1 |= (pEventCfg->Polarity << 18);
3796       hrtim_eecr1 |= (pEventCfg->Sensitivity << 18);
3797       /* Update the HRTIM registers (all bit fields but EE4FAST bit) */
3798       HRTIMx->HRTIM_COMMON.EECR1 = hrtim_eecr1;
3799       /* Update the HRTIM registers (EE4FAST bit) */
3800       hrtim_eecr1 |= (pEventCfg->FastMode << 18);
3801       HRTIMx->HRTIM_COMMON.EECR1 = hrtim_eecr1;
3802     }
3803     break;
3804     case HRTIM_EVENT_5:
3805     {
3806       hrtim_eecr1 &= ~(HRTIM_EECR1_EE5SRC | HRTIM_EECR1_EE5POL | HRTIM_EECR1_EE5SNS | HRTIM_EECR1_EE5FAST);
3807       hrtim_eecr1 |= (pEventCfg->Source << 24);
3808       hrtim_eecr1 |= (pEventCfg->Polarity << 24);
3809       hrtim_eecr1 |= (pEventCfg->Sensitivity << 24);
3810       /* Update the HRTIM registers (all bit fields but EE5FAST bit) */
3811       HRTIMx->HRTIM_COMMON.EECR1 = hrtim_eecr1;
3812       /* Update the HRTIM registers (EE5FAST bit) */
3813       hrtim_eecr1 |= (pEventCfg->FastMode << 24);
3814       HRTIMx->HRTIM_COMMON.EECR1 = hrtim_eecr1;
3815     }
3816     break;
3817     case HRTIM_EVENT_6:
3818     {
3819       hrtim_eecr2 &= ~(HRTIM_EECR2_EE6SRC | HRTIM_EECR2_EE6POL | HRTIM_EECR2_EE6SNS);
3820       hrtim_eecr2 |= pEventCfg->Source;
3821       hrtim_eecr2 |= pEventCfg->Polarity;
3822       hrtim_eecr2 |= pEventCfg->Sensitivity;
3823       hrtim_eecr3 &= ~(HRTIM_EECR3_EE6F);
3824       hrtim_eecr3 |= pEventCfg->Filter;
3825       /* Update the HRTIM registers */
3826       HRTIMx->HRTIM_COMMON.EECR2 = hrtim_eecr2;
3827       HRTIMx->HRTIM_COMMON.EECR3 = hrtim_eecr3;
3828     }
3829     break;
3830     case HRTIM_EVENT_7:
3831     {
3832       hrtim_eecr2 &= ~(HRTIM_EECR2_EE7SRC | HRTIM_EECR2_EE7POL | HRTIM_EECR2_EE7SNS);
3833       hrtim_eecr2 |= (pEventCfg->Source << 6);
3834       hrtim_eecr2 |= (pEventCfg->Polarity << 6);
3835       hrtim_eecr2 |= (pEventCfg->Sensitivity << 6);
3836       hrtim_eecr3 &= ~(HRTIM_EECR3_EE7F);
3837       hrtim_eecr3 |= (pEventCfg->Filter << 6);
3838       /* Update the HRTIM registers */
3839       HRTIMx->HRTIM_COMMON.EECR2 = hrtim_eecr2;
3840       HRTIMx->HRTIM_COMMON.EECR3 = hrtim_eecr3;
3841     }
3842     break;
3843     case HRTIM_EVENT_8:
3844     {
3845       hrtim_eecr2 &= ~(HRTIM_EECR2_EE8SRC | HRTIM_EECR2_EE8POL | HRTIM_EECR2_EE8SNS);
3846       hrtim_eecr2 |= (pEventCfg->Source << 12);
3847       hrtim_eecr2 |= (pEventCfg->Polarity << 12);
3848       hrtim_eecr2 |= (pEventCfg->Sensitivity << 12);
3849       hrtim_eecr3 &= ~(HRTIM_EECR3_EE8F);
3850       hrtim_eecr3 |= (pEventCfg->Filter << 12);
3851       /* Update the HRTIM registers */
3852       HRTIMx->HRTIM_COMMON.EECR2 = hrtim_eecr2;
3853       HRTIMx->HRTIM_COMMON.EECR3 = hrtim_eecr3;
3854     }
3855     break;
3856     case HRTIM_EVENT_9:
3857     {
3858       hrtim_eecr2 &= ~(HRTIM_EECR2_EE9SRC | HRTIM_EECR2_EE9POL | HRTIM_EECR2_EE9SNS);
3859       hrtim_eecr2 |= (pEventCfg->Source << 18);
3860       hrtim_eecr2 |= (pEventCfg->Polarity << 18);
3861       hrtim_eecr2 |= (pEventCfg->Sensitivity << 18);
3862       hrtim_eecr3 &= ~(HRTIM_EECR3_EE9F);
3863       hrtim_eecr3 |= (pEventCfg->Filter << 18);
3864       /* Update the HRTIM registers */
3865       HRTIMx->HRTIM_COMMON.EECR2 = hrtim_eecr2;
3866       HRTIMx->HRTIM_COMMON.EECR3 = hrtim_eecr3;
3867     }
3868     break;
3869     case HRTIM_EVENT_10:
3870     {
3871       hrtim_eecr2 &= ~(HRTIM_EECR2_EE10SRC | HRTIM_EECR2_EE10POL | HRTIM_EECR2_EE10SNS);
3872       hrtim_eecr2 |= (pEventCfg->Source << 24);
3873       hrtim_eecr2 |= (pEventCfg->Polarity << 24);
3874       hrtim_eecr2 |= (pEventCfg->Sensitivity << 24);
3875       hrtim_eecr3 &= ~(HRTIM_EECR3_EE10F);
3876       hrtim_eecr3 |= (pEventCfg->Filter << 24);
3877       /* Update the HRTIM registers */
3878       HRTIMx->HRTIM_COMMON.EECR2 = hrtim_eecr2;
3879       HRTIMx->HRTIM_COMMON.EECR3 = hrtim_eecr3;
3880     }
3881     break;
3882     default:
3883     break;
3884   }
3885 }
3886
3887 /**
3888   * @brief  Configures the timer counter reset 
3889   * @param  HRTIMx: pointer to HRTIMx peripheral
3890   * @param  TimerIdx: Timer index
3891   * @param  Event: Event channel identifier
3892   * @retval None
3893   */
3894 void HRTIM_TIM_ResetConfig(HRTIM_TypeDef * HRTIMx,
3895                            uint32_t TimerIdx,
3896                            uint32_t Event)
3897 {
3898   switch (Event)
3899   {
3900     case HRTIM_EVENT_1:
3901     {
3902       HRTIMx->HRTIM_TIMERx[TimerIdx].RSTxR = HRTIM_TIMRESETTRIGGER_EEV_1;
3903     }
3904     break;
3905     case HRTIM_EVENT_2:
3906     {
3907       HRTIMx->HRTIM_TIMERx[TimerIdx].RSTxR = HRTIM_TIMRESETTRIGGER_EEV_2;
3908     }
3909     break;
3910     case HRTIM_EVENT_3:
3911     {
3912       HRTIMx->HRTIM_TIMERx[TimerIdx].RSTxR = HRTIM_TIMRESETTRIGGER_EEV_3;
3913     }
3914     break;
3915     case HRTIM_EVENT_4:
3916     {
3917       HRTIMx->HRTIM_TIMERx[TimerIdx].RSTxR = HRTIM_TIMRESETTRIGGER_EEV_4;
3918     }
3919     break;
3920     case HRTIM_EVENT_5:
3921     {
3922       HRTIMx->HRTIM_TIMERx[TimerIdx].RSTxR = HRTIM_TIMRESETTRIGGER_EEV_5;
3923     }
3924     break;
3925     case HRTIM_EVENT_6:
3926     {
3927       HRTIMx->HRTIM_TIMERx[TimerIdx].RSTxR = HRTIM_TIMRESETTRIGGER_EEV_6;
3928     }
3929     break;
3930     case HRTIM_EVENT_7:
3931     {
3932       HRTIMx->HRTIM_TIMERx[TimerIdx].RSTxR = HRTIM_TIMRESETTRIGGER_EEV_7;
3933     }
3934     break;
3935     case HRTIM_EVENT_8:
3936     {
3937       HRTIMx->HRTIM_TIMERx[TimerIdx].RSTxR = HRTIM_TIMRESETTRIGGER_EEV_8;
3938     }
3939     break;
3940     case HRTIM_EVENT_9:
3941     {
3942       HRTIMx->HRTIM_TIMERx[TimerIdx].RSTxR = HRTIM_TIMRESETTRIGGER_EEV_9;
3943     }
3944     break;
3945     case HRTIM_EVENT_10:
3946     {
3947       HRTIMx->HRTIM_TIMERx[TimerIdx].RSTxR = HRTIM_TIMRESETTRIGGER_EEV_10;
3948     }
3949     break;
3950     default:
3951     break;
3952   }
3953 }
3954 /**
3955   * @}
3956   */
3957 /**
3958   * @}
3959   */
3960
3961 /**
3962   * @}
3963   */
3964
3965 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
3966
3967
3968