summaryrefslogtreecommitdiff
path: root/tool/mbed/mbed-sdk/libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F3XX/stm32f30x_hrtim.c
blob: 84c09d565fa27090834a3801707e854a4c83e5fb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
/**
  ******************************************************************************
  * @file    stm32f30x_hrtim.c
  * @author  MCD Application Team
  * @version V1.1.0
  * @date    27-February-2014
  * @brief   HRTIMx module driver.
  *    
  *          This file provides firmware functions to manage the following 
  *          functionalities of the HRTIMx peripheral:
  *           + Initialization/de-initialization methods
  *           + I/O operation methods
  *           + Peripheral Control methods 
  *         
  @verbatim
================================================================================
                    ##### <HRTIM specific features> #####
================================================================================
           
  [..] < HRTIM introduction: 
       (#) The high-resolution timer can generate up to 10 digital signals with
           highly accurate timings.
           It is primarily intended to drive power conversion systems such as 
           switch mode power supplies or lighting systems, 
           but can be of general purpose usage, whenever a very fine timing 
           resolution is expected.

       (#) Its modular architecture allows to generate either independent or 
           coupled waveforms. 
           The wave-shape is defined by self-contained timings 
           (using counters and compare units) and a broad range of external events,
           such as analog or digital feedbacks and synchronisation signals. 
           This allows to produce a large variety of control signal (PWM, phase-shifted,
           constant Ton,...) and address most of conversion topologies.

       (#) For control and monitoring purposes, the timer has also timing measure 
           capabilities and links to built-in ADC and DAC converters. 
           Last, it features light-load management mode and is able to handle 
           various fault schemes for safe shut-down purposes.
                 
   
            ##### How to use this driver #####
================================================================================
        [..] This driver provides functions to configure and program the HRTIM 
        of all stm32f33x devices.
        These functions are split in 9 groups: 
     
        (#) HRTIM Simple TimeBase management: this group includes all needed functions 
            to configure the HRTIM Timebase unit:
                 (++) Initializes the HRTIMx timer in simple time base mode 
                 (++) Start/Stop the time base generation
                 (++) Deinitialize the HRTIM peripheral  
    
                   
       (#) HRTIM simple Output Compare management: this group includes all needed 
           functions to configure the Compare unit used in Output compare mode: 
                 (++) Initializes the HRTIMx timer time base unit 
                 (++) Configure the compare unit in in simple Output Compare mode
                 (++) Start/Stop the Output compare generation    
                    
       (#) HRTIM simple PWM management: this group includes all needed 
           functions to configure the Compare unit used in PWM mode: 
                 (++) Initializes the HRTIMx timer time base unit 
                 (++) Configure the compare unit in in simple PWM mode
                 (++) Start/Stop the PWM generation      
                     
       (#) HRTIM simple Capture management: this group includes all needed 
           functions to configure the Capture unit used in Capture mode: 
                 (++) Initializes the HRTIMx timer time base unit 
                 (++) Configure the compare unit in in simple Capture mode
                 (++) Start/Stop the Capture mode

       (#) HRTIM simple One Pulse management: this group includes all needed 
           functions to configure the Capture unit and Compare unit used in One Pulse mode: 
                 (++) Initializes the HRTIMx timer time base unit 
                 (++) Configure the compare unit and the capture unit in in simple One Pulse mode
                 (++) Start/Stop the One Pulse mode generation 
                   
       (#) HRTIM Waveform management: this group includes all needed 
           functions to configure the HRTIM possible waveform mode: 
                 (++) Initializes the HRTIMx timer Master time base unit 
                 (++) Initializes the HRTIMx timer Slaves time base unit
                 (++) Configures the HRTIMx timer Compare unit  
                 (++) Configures the HRTIMx Slave timer Capture unit 
                 (++) Configures the HRTIMx timer Output unit 
                 (++) Configures the HRTIMx timer DeadTime / Chopper / Burst features 
                 (++) Configures the HRTIMx timer Fault / External event features 
                 (++) Configures the HRTIMx timer Synchronization features: Internal/External connection, DACs,... 
                 (++) Configures the HRTIMx timer Synchronization features: ADCs Triggers  
                 (++) HRTIMx timer Outputs Start/Stop  
                 (++) Start/Stop the HRTIMx Timer counters            
                               
        (#) HRTIM interrupts, DMA and flags management
                 (++) Enable/Disable interrupt sources
                 (++) Get flags status
                 (++) Clear flags/ Pending bits
                 (++) Enable/Disable DMA requests 
                 (++) Configure DMA burst mode
       
        (#) TIM specific interface management, this group includes all 
            needed functions to use the specific TIM interface:
                 (++) HRTIMx timer DLL calibration      
  
  @endverbatim
  ******************************************************************************
  * @attention
  *
  * <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
  *
  * Redistribution and use in source and binary forms, with or without modification,
  * are permitted provided that the following conditions are met:
  *   1. Redistributions of source code must retain the above copyright notice,
  *      this list of conditions and the following disclaimer.
  *   2. Redistributions in binary form must reproduce the above copyright notice,
  *      this list of conditions and the following disclaimer in the documentation
  *      and/or other materials provided with the distribution.
  *   3. Neither the name of STMicroelectronics nor the names of its contributors
  *      may be used to endorse or promote products derived from this software
  *      without specific prior written permission.
  *
  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
  ******************************************************************************  
  */ 
/* Includes ------------------------------------------------------------------*/
#include "stm32f30x_hrtim.h"

/** @addtogroup STM32F30x_StdPeriph_Driver
  * @{
  */

/** @defgroup HRTIM 
  * @brief HRTIM driver module
  * @{
  */

/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
#define HRTIM_FLTR_FLTxEN (HRTIM_FLTR_FLT1EN |\
                           HRTIM_FLTR_FLT2EN |\
                           HRTIM_FLTR_FLT3EN |\
                           HRTIM_FLTR_FLT4EN | \
                           HRTIM_FLTR_FLT5EN)

#define HRTIM_TIMCR_TIMUPDATETRIGGER (HRTIM_TIMUPDATETRIGGER_MASTER  |\
                                      HRTIM_TIMUPDATETRIGGER_TIMER_A |\
                                      HRTIM_TIMUPDATETRIGGER_TIMER_B |\
                                      HRTIM_TIMUPDATETRIGGER_TIMER_C |\
                                      HRTIM_TIMUPDATETRIGGER_TIMER_D |\
                                      HRTIM_TIMUPDATETRIGGER_TIMER_E)

#define HRTIM_TIM_OFFSET      (uint32_t)0x00000080
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
static uint32_t TimerIdxToTimerId[] = 
{
  HRTIM_TIMERID_TIMER_A,
  HRTIM_TIMERID_TIMER_B,
  HRTIM_TIMERID_TIMER_C,
  HRTIM_TIMERID_TIMER_D,
  HRTIM_TIMERID_TIMER_E,
  HRTIM_TIMERID_MASTER,
};

/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/
static void HRTIM_MasterBase_Config(HRTIM_TypeDef* HRTIMx, HRTIM_BaseInitTypeDef* HRTIM_BaseInitStruc);
static void HRTIM_TimingUnitBase_Config(HRTIM_TypeDef * HRTIMx, uint32_t TimerIdx, HRTIM_BaseInitTypeDef* HRTIM_BaseInitStruct);
static void HRTIM_MasterWaveform_Config(HRTIM_TypeDef * HRTIMx, HRTIM_TimerInitTypeDef * TimerInit);
static void HRTIM_TimingUnitWaveform_Config(HRTIM_TypeDef * HRTIMx, 
                                            uint32_t TimerIdx, 
                                            HRTIM_TimerInitTypeDef * TimerInit);
static void HRTIM_CompareUnitConfig(HRTIM_TypeDef * HRTIMx,
                                    uint32_t TimerIdx,
                                    uint32_t CompareUnit,
                                    HRTIM_CompareCfgTypeDef * CompareCfg);
static void HRTIM_CaptureUnitConfig(HRTIM_TypeDef * HRTIMx,
                                    uint32_t TimerIdx,
                                    uint32_t CaptureUnit,
                                    uint32_t Event);
static void HRTIM_OutputConfig(HRTIM_TypeDef * HRTIMx,
                                uint32_t TimerIdx,
                                uint32_t Output,
                                HRTIM_OutputCfgTypeDef * OutputCfg);
static void HRTIM_ExternalEventConfig(HRTIM_TypeDef * HRTIMx,
                                      uint32_t Event,
                                      HRTIM_EventCfgTypeDef * EventCfg);
static void HRTIM_TIM_ResetConfig(HRTIM_TypeDef * HRTIMx,
                                  uint32_t TimerIdx,
                                  uint32_t Event);  
  /** @defgroup HRTIM_Private_Functions
  * @{
  */

/** @defgroup HRTIM_Group1 Initialization/de-initialization methods 
 *  @brief    Initialization and Configuration functions 
 *
@verbatim    
 ===============================================================================
              ##### Initialization/de-initialization methods #####
 ===============================================================================
    [..]  This section provides functions allowing to:
          (+)Initializes timer in basic time base mode
          (+)Initializes timer in basic OC mode
          (+)Initializes timer in basic PWM mode
          (+)Initializes timer in basic Capture mode
          (+)Initializes timer in One Pulse mode
          (+)Initializes a timer operating in waveform mode
          (+)De-initializes the HRTIMx timer
 
@endverbatim
  * @{
  */

/**
  * @brief  Initializes the HRTIMx timer in basic time base mode 
  * @param  HRTIMx: pointer to HRTIMx peripheral
  * @param  TimerIdx: Timer index
  *                   This parameter can be one of the following values:
  *                   @arg 0x0 for master timer
  *                   @arg 0x1 to 0x5 for timers A to E
  * @note   The time-base unit initialization parameters specify:
  *           The timer counter operating mode (continuous, one shot)
  *           The timer clock prescaler
  *           The timer period 
  *           The timer repetition counter.
  * @retval None
  */
void HRTIM_SimpleBase_Init(HRTIM_TypeDef* HRTIMx, uint32_t TimerIdx, HRTIM_BaseInitTypeDef* HRTIM_BaseInitStruct)
{
  /* Check the parameters */
  assert_param(IS_HRTIM_TIMERINDEX(TimerIdx));
  assert_param(IS_HRTIM_MODE(HRTIM_BaseInitStruct->Mode));
   
  if (TimerIdx == HRTIM_TIMERINDEX_MASTER)
  {
    /* Configure master timer */
    HRTIM_MasterBase_Config(HRTIMx, HRTIM_BaseInitStruct);
  }
  else
  {
    /* Configure timing unit */
    HRTIM_TimingUnitBase_Config(HRTIMx, TimerIdx, HRTIM_BaseInitStruct);
  }
}

/**
  * @brief  De-initializes a timer operating in all mode 
  * @param  HRTIMx: pointer to HRTIMx peripheral 
  * @retval None
  */
void HRTIM_DeInit(HRTIM_TypeDef* HRTIMx)
{
  /* Check the parameters */
    RCC_APB2PeriphResetCmd(RCC_APB2Periph_HRTIM1, ENABLE);
    RCC_APB2PeriphResetCmd(RCC_APB2Periph_HRTIM1, DISABLE);  
 }

/**
  * @brief  Initializes the HRTIMx timer in basic output compare mode 
  * @param  HRTIMx: pointer to HRTIMx peripheral
  * @param  TimerIdx: Timer index
  *                   This parameter can be one of the following values:
  *                   @arg 0x1 to 0x5 for timers A to E
  * @note   Initializes the time-base unit of the timer and prepare it to
  *         operate in output compare mode
  * @retval None
  */
void HRTIM_SimpleOC_Init(HRTIM_TypeDef * HRTIMx, uint32_t TimerIdx, HRTIM_BaseInitTypeDef* HRTIM_BaseInitStruct)
{
  /* Check the parameters */
  assert_param(IS_HRTIM_TIMERINDEX(TimerIdx));
  assert_param(IS_HRTIM_MODE(HRTIM_BaseInitStruct->Mode));
   
  /* Configure timing unit */
  HRTIM_TimingUnitBase_Config(HRTIMx, TimerIdx, HRTIM_BaseInitStruct);
}

/**
  * @brief  Initializes the HRTIMx timer in basic PWM mode 
  * @param  HRTIMx: pointer to HRTIMx peripheral
  * @param  TimerIdx: Timer index
  *                   This parameter can be one of the following values:
  *                   @arg 0x1 to 0x5 for timers A to E
  * @note   Initializes the time-base unit of the timer and prepare it to
  *         operate in capture mode
  * @retval None
  */
void HRTIM_SimplePWM_Init(HRTIM_TypeDef * HRTIMx, uint32_t TimerIdx, HRTIM_BaseInitTypeDef* HRTIM_BaseInitStruct)
{
  /* Check the parameters */
  assert_param(IS_HRTIM_TIMERINDEX(TimerIdx));
  assert_param(IS_HRTIM_MODE(HRTIM_BaseInitStruct->Mode));
  
  /* Configure timing unit */
  HRTIM_TimingUnitBase_Config(HRTIMx, TimerIdx, HRTIM_BaseInitStruct);
}

/**
  * @brief  Initializes a timer operating in basic capture mode 
  * @param  HRTIMx: pointer to HRTIMx peripheral
  * @param  TimerIdx: Timer index
  *                   This parameter can be one of the following values:
  *                   @arg 0x1 to 0x5 for timers A to E 
  * @retval None
  */
void HRTIM_SimpleCapture_Init(HRTIM_TypeDef * HRTIMx, uint32_t TimerIdx, HRTIM_BaseInitTypeDef* HRTIM_BaseInitStruct)
{
  /* Check the parameters */
  assert_param(IS_HRTIM_TIMERINDEX(TimerIdx));
  assert_param(IS_HRTIM_MODE(HRTIM_BaseInitStruct->Mode));
  
  /* Configure timing unit */
  HRTIM_TimingUnitBase_Config(HRTIMx, TimerIdx, HRTIM_BaseInitStruct);
}

/**
  * @brief  Initializes the HRTIMx timer in basic one pulse mode 
  * @param  HRTIMx: pointer to  HRTIMx peripheral
  * @param  TimerIdx: Timer index
  *                   This parameter can be one of the following values:
  *                   @arg 0x1 to 0x5 for timers A to E
  * @note   Initializes the time-base unit of the timer and prepare it to
  *         operate in one pulse mode. In this mode the counter operates
  *         in single shot mode (retriggerable or not)
  * @retval None
  */
void HRTIM_SimpleOnePulse_Init(HRTIM_TypeDef * HRTIMx, uint32_t TimerIdx, HRTIM_BaseInitTypeDef* HRTIM_BaseInitStruct)
{
  /* Check the parameters */
  assert_param(IS_HRTIM_TIMERINDEX(TimerIdx));
  assert_param(IS_HRTIM_MODE(HRTIM_BaseInitStruct->Mode));
  
  /* Configure timing unit */
  HRTIM_TimingUnitBase_Config(HRTIMx, TimerIdx, HRTIM_BaseInitStruct);
}

/**
  * @brief  Initializes a timer operating in waveform mode 
  * @param  HRTIMx: pointer to HRTIMx peripheral
  * @param  TimerIdx: Timer index
  *                   This parameter can be one of the following values:
  *                   @arg 0x0 for master timer
  *                   @arg 0x1 to 0x5 for timers A to E 
  * @param  pTimerInit: pointer to the timer initialization data structure
  * @retval None
  */
void HRTIM_Waveform_Init(HRTIM_TypeDef * HRTIMx,
                                         uint32_t TimerIdx,
                                         HRTIM_BaseInitTypeDef* HRTIM_BaseInitStruct,
                                         HRTIM_TimerInitTypeDef* HRTIM_TimerInitStruct)
{
  /* Check the parameters */
  assert_param(IS_HRTIM_HALFMODE(HRTIM_TimerInitStruct->HalfModeEnable));
  assert_param(IS_HRTIM_SYNCSTART(HRTIM_TimerInitStruct->StartOnSync));
  assert_param(IS_HRTIM_SYNCRESET(HRTIM_TimerInitStruct->ResetOnSync));
  assert_param(IS_HRTIM_DACSYNC(HRTIM_TimerInitStruct->DACSynchro));
  assert_param(IS_HRTIM_PRELOAD(HRTIM_TimerInitStruct->PreloadEnable));
  assert_param(IS_HRTIM_TIMERBURSTMODE(HRTIM_TimerInitStruct->BurstMode));
  assert_param(IS_HRTIM_UPDATEONREPETITION(HRTIM_TimerInitStruct->RepetitionUpdate));
 
  if (TimerIdx == HRTIM_TIMERINDEX_MASTER)
  {
    /* Check parameters */
    assert_param(IS_HRTIM_UPDATEGATING_MASTER(HRTIM_TimerInitStruct->UpdateGating));  
    
    /* Configure master timer */
    HRTIM_MasterBase_Config(HRTIMx, HRTIM_BaseInitStruct);
    HRTIM_MasterWaveform_Config(HRTIMx, HRTIM_TimerInitStruct);
  }
  else
  {
    /* Check parameters */
    assert_param(IS_HRTIM_UPDATEGATING_TIM(HRTIM_TimerInitStruct->UpdateGating));  
    
    /* Configure timing unit */
    HRTIM_TimingUnitBase_Config(HRTIMx, TimerIdx, HRTIM_BaseInitStruct);
    HRTIM_TimingUnitWaveform_Config(HRTIMx, TimerIdx, HRTIM_TimerInitStruct);
  }
}

/**
  * @}
  */

/** @defgroup HRTIM_Group2 I/O operation methods 
 *  @brief   Data transfers functions 
 *
@verbatim   
 ===============================================================================
                      ##### IO operation methods #####
 ===============================================================================  
    [..]
    This subsection provides a set of functions allowing to manage the HRTIMx data 
    transfers.
    (+) Starts the DLL calibration.
    (+) Starts / stops the counter of a timer operating in basic time base mode
    (+) Starts / stops the output compare signal generation on the designed timer output
    (+) Starts / stops the PWM output signal generation on the designed timer output
    (+) Enables / disables a basic capture on the designed capture unit

@endverbatim
  * @{
  */

/**
  * @brief  Starts the DLL calibration
  * @param  HRTIMx: pointer to HRTIMx peripheral
  * @param  CalibrationRate: DLL calibration period
  *                    This parameter can be one of the following values:
  *                    @arg HRTIM_CALIBRATIONRATE_7300: 7.3 ms
  *                    @arg HRTIM_CALIBRATIONRATE_910: 910 us
  *                    @arg HRTIM_CALIBRATIONRATE_114: 114 us
  *                    @arg HRTIM_CALIBRATIONRATE_14: 14 us
  * @retval None
  */
void HRTIM_DLLCalibrationStart(HRTIM_TypeDef * HRTIMx, uint32_t CalibrationRate)
{
  uint32_t HRTIM_dllcr;
  
   /* Check the parameters */
  assert_param(IS_HRTIM_CALIBRATIONRATE(CalibrationRate));

  /* Configure DLL Calibration */
  HRTIM_dllcr = (HRTIMx->HRTIM_COMMON).DLLCR;
  
  /* Set the Calibration rate */
  HRTIM_dllcr &= ~(HRTIM_DLLCR_CALRTE);
  HRTIM_dllcr |= CalibrationRate;
    
  /* Start DLL calibration */
   HRTIM_dllcr |= HRTIM_DLLCR_CAL;
               
  /* Update HRTIMx register */
  (HRTIMx->HRTIM_COMMON).DLLCR = HRTIM_dllcr;
  
}
/**
  * @brief  Starts the counter of a timer operating in basic time base mode
  * @param  HRTIMx: pointer to HRTIM peripheral
  * @param  TimerIdx: Timer index
  *                   This parameter can be one of the following values:
  *                   @arg 0x5 for master timer
  *                   @arg 0x0 to 0x4 for timers A to E 
  * @retval None
  */
void HRTIM_SimpleBaseStart(HRTIM_TypeDef * HRTIMx, uint32_t TimerIdx)
{  
   /* Check the parameters */
  assert_param(IS_HRTIM_TIMERINDEX(TimerIdx));
  
  /* Enable the timer counter */
  __HRTIM_ENABLE(HRTIMx, TimerIdxToTimerId[TimerIdx]);
}

/**
  * @brief  Stops the counter of a timer operating in basic time base mode
  * @param  HRTIMx: pointer to HRTIM peripheral
  * @param  TimerIdx: Timer index
  *                   This parameter can be one of the following values:
  *                   @arg 0x5 for master timer
  *                   @arg 0x0 to 0x4 for timers A to E 
  * @retval None
  */
void HRTIM_SimpleBaseStop(HRTIM_TypeDef * HRTIMx, uint32_t TimerIdx)
{
   /* Check the parameters */
  assert_param(IS_HRTIM_TIMERINDEX(TimerIdx)); 
  
  /* Disable the timer counter */
  __HRTIM_DISABLE(HRTIMx, TimerIdxToTimerId[TimerIdx]);
}

/**
  * @brief  Starts the output compare signal generation on the designed timer output 
  * @param  HRTIMx: pointer to HRTIM peripheral
  * @param  TimerIdx: Timer index
  *                   This parameter can be one of the following values:
  *                   @arg 0x0 to 0x4 for timers A to E 
  * @param  OCChannel: Timer output
  *                    This parameter can be one of the following values:
  *                    @arg HRTIM_OUTPUT_TA1: Timer A - Output 1
  *                    @arg HRTIM_OUTPUT_TA2: Timer A - Output 2
  *                    @arg HRTIM_OUTPUT_TB1: Timer B - Output 1
  *                    @arg HRTIM_OUTPUT_TB2: Timer B - Output 2
  *                    @arg HRTIM_OUTPUT_TC1: Timer C - Output 1
  *                    @arg HRTIM_OUTPUT_TC2: Timer C - Output 2
  *                    @arg HRTIM_OUTPUT_TD1: Timer D - Output 1
  *                    @arg HRTIM_OUTPUT_TD2: Timer D - Output 2
  *                    @arg HRTIM_OUTPUT_TE1: Timer E - Output 1
  *                    @arg HRTIM_OUTPUT_TE2: Timer E - Output 2
  * @retval None
  */
void HRTIM_SimpleOCStart(HRTIM_TypeDef * HRTIMx,
                                         uint32_t TimerIdx,
                                         uint32_t OCChannel)
{
   /* Check the parameters */
  assert_param(IS_HRTIM_TIMER_OUTPUT(TimerIdx, OCChannel));
  
  /* Enable the timer output */
   (HRTIMx->HRTIM_COMMON).OENR |= OCChannel;
       
    /* Enable the timer counter */
  __HRTIM_ENABLE(HRTIMx, TimerIdxToTimerId[TimerIdx]);
  
}

/**
  * @brief  Stops the output compare signal generation on the designed timer output 
  * @param  HRTIMx: pointer to HRTIM peripheral
  * @param  TimerIdx: Timer index
  *                   This parameter can be one of the following values:
  *                   @arg 0x0 to 0x4 for timers A to E 
  * @param  OCChannel: Timer output
  *                    This parameter can be one of the following values:
  *                    @arg HRTIM_OUTPUT_TA1: Timer A - Output 1
  *                    @arg HRTIM_OUTPUT_TA2: Timer A - Output 2
  *                    @arg HRTIM_OUTPUT_TB1: Timer B - Output 1
  *                    @arg HRTIM_OUTPUT_TB2: Timer B - Output 2
  *                    @arg HRTIM_OUTPUT_TC1: Timer C - Output 1
  *                    @arg HRTIM_OUTPUT_TC2: Timer C - Output 2
  *                    @arg HRTIM_OUTPUT_TD1: Timer D - Output 1
  *                    @arg HRTIM_OUTPUT_TD2: Timer D - Output 2
  *                    @arg HRTIM_OUTPUT_TE1: Timer E - Output 1
  *                    @arg HRTIM_OUTPUT_TE2: Timer E - Output 2
  * @retval None
  */
void HRTIM_SimpleOCStop(HRTIM_TypeDef * HRTIMx,
                                        uint32_t TimerIdx,
                                        uint32_t OCChannel)
{
   /* Check the parameters */
  assert_param(IS_HRTIM_TIMER_OUTPUT(TimerIdx, OCChannel));
  
  /* Disable the timer output */
  HRTIMx->HRTIM_COMMON.DISR |= OCChannel;
    
  /* Disable the timer counter */
   __HRTIM_DISABLE(HRTIMx, TimerIdxToTimerId[TimerIdx]);
}

/**
  * @brief  Starts the PWM output signal generation on the designed timer output
  * @param  HRTIMx: pointer to HRTIM peripheral
  * @param  TimerIdx: Timer index
  *                   This parameter can be one of the following values:
  *                   @arg 0x0 to 0x4 for timers A to E 
  * @param  PWMChannel: Timer output
  *                    This parameter can be one of the following values:
  *                    @arg HRTIM_OUTPUT_TA1: Timer A - Output 1
  *                    @arg HRTIM_OUTPUT_TA2: Timer A - Output 2
  *                    @arg HRTIM_OUTPUT_TB1: Timer B - Output 1
  *                    @arg HRTIM_OUTPUT_TB2: Timer B - Output 2
  *                    @arg HRTIM_OUTPUT_TC1: Timer C - Output 1
  *                    @arg HRTIM_OUTPUT_TC2: Timer C - Output 2
  *                    @arg HRTIM_OUTPUT_TD1: Timer D - Output 1
  *                    @arg HRTIM_OUTPUT_TD2: Timer D - Output 2
  *                    @arg HRTIM_OUTPUT_TE1: Timer E - Output 1
  *                    @arg HRTIM_OUTPUT_TE2: Timer E - Output 2
  * @retval None
  */
void HRTIM_SimplePWMStart(HRTIM_TypeDef * HRTIMx,
                                          uint32_t TimerIdx,
                                          uint32_t PWMChannel)
{
   /* Check the parameters */
  assert_param(IS_HRTIM_TIMER_OUTPUT(TimerIdx, PWMChannel));
  
  /* Enable the timer output */
  HRTIMx->HRTIM_COMMON.OENR |= PWMChannel;
    
  /* Enable the timer counter */
  __HRTIM_ENABLE(HRTIMx, TimerIdxToTimerId[TimerIdx]);
}

/**
  * @brief  Stops the PWM output signal generation on the designed timer output
  * @param  HRTIMx: pointer to HRTIM peripheral
  * @param  TimerIdx: Timer index
  *                   This parameter can be one of the following values:
  *                   @arg 0x0 to 0x4 for timers A to E 
  * @param  PWMChannel: Timer output
  *                    This parameter can be one of the following values:
  *                    @arg HRTIM_OUTPUT_TA1: Timer A - Output 1
  *                    @arg HRTIM_OUTPUT_TA2: Timer A - Output 2
  *                    @arg HRTIM_OUTPUT_TB1: Timer B - Output 1
  *                    @arg HRTIM_OUTPUT_TB2: Timer B - Output 2
  *                    @arg HRTIM_OUTPUT_TC1: Timer C - Output 1
  *                    @arg HRTIM_OUTPUT_TC2: Timer C - Output 2
  *                    @arg HRTIM_OUTPUT_TD1: Timer D - Output 1
  *                    @arg HRTIM_OUTPUT_TD2: Timer D - Output 2
  *                    @arg HRTIM_OUTPUT_TE1: Timer E - Output 1
  *                    @arg HRTIM_OUTPUT_TE2: Timer E - Output 2
  * @retval None
  */
void HRTIM_SimplePWMStop(HRTIM_TypeDef * HRTIMx,
                                         uint32_t TimerIdx,
                                         uint32_t PWMChannel)
{
   /* Check the parameters */
  assert_param(IS_HRTIM_TIMER_OUTPUT(TimerIdx, PWMChannel));
 
  /* Disable the timer output */
  HRTIMx->HRTIM_COMMON.DISR |= PWMChannel;
    
  /* Disable the timer counter */
   __HRTIM_DISABLE(HRTIMx, TimerIdxToTimerId[TimerIdx]);
}

/**
  * @brief  Enables a basic capture on the designed capture unit
  * @param  HRTIMx: pointer to HRTIM peripheral
  * @param  TimerIdx: Timer index
  *                   This parameter can be one of the following values:
  *                   @arg 0x0 to 0x4 for timers A to E 
  * @param  CaptureChannel: Timer output
  *                    This parameter can be one of the following values: 
  *                    @arg HRTIM_CAPTUREUNIT_1: Capture unit 1
  *                    @arg HRTIM_CAPTUREUNIT_2: Capture unit 2
  * @retval None
  * @note  The external event triggering the capture is available for all timing 
  *        units. It can be used directly and is active as soon as the timing 
  *        unit counter is enabled.
  */
void HRTIM_SimpleCaptureStart(HRTIM_TypeDef * HRTIMx,
                                              uint32_t TimerIdx,
                                              uint32_t CaptureChannel)
{
  /* Enable the timer counter */
  __HRTIM_ENABLE(HRTIMx, TimerIdxToTimerId[TimerIdx]);

}

/**
  * @brief  Disables a basic capture on the designed capture unit 
  * @param  HRTIMx: pointer to HRTIMx peripheral
  * @param  TimerIdx: Timer index
  *                   This parameter can be one of the following values:
  *                   @arg 0x0 to 0x4 for timers A to E 
  * @param  CaptureChannel: Timer output
  *                    This parameter can be one of the following values: 
  *                    @arg HRTIM_CAPTUREUNIT_1: Capture unit 1
  *                    @arg HRTIM_CAPTUREUNIT_2: Capture unit 2
  * @retval None
  */
void HRTIM_SimpleCaptureStop(HRTIM_TypeDef * HRTIMx,
                                             uint32_t TimerIdx,
                                             uint32_t CaptureChannel)
{
   /* Check the parameters */
  assert_param(IS_HRTIM_TIMING_UNIT(TimerIdx));
  assert_param(IS_HRTIM_CAPTUREUNIT(CaptureChannel));
    
  /* Set the capture unit trigger */
  switch (CaptureChannel)
  {
    case HRTIM_CAPTUREUNIT_1:
    {
      HRTIMx->HRTIM_TIMERx[TimerIdx].CPT1xCR = HRTIM_CAPTURETRIGGER_NONE;
    }
    break;
    case HRTIM_CAPTUREUNIT_2:
    {
      HRTIMx->HRTIM_TIMERx[TimerIdx].CPT2xCR = HRTIM_CAPTURETRIGGER_NONE;
    }
    break;
    default:
    break;  
  }
  
  /* Disable the timer counter */
  if ((HRTIMx->HRTIM_TIMERx[TimerIdx].CPT1xCR == HRTIM_CAPTURETRIGGER_NONE) &&
      (HRTIMx->HRTIM_TIMERx[TimerIdx].CPT2xCR == HRTIM_CAPTURETRIGGER_NONE))
  {
    __HRTIM_DISABLE(HRTIMx, TimerIdxToTimerId[TimerIdx]);
  }
  
}

/**
  * @brief  Enables the basic one pulse signal generation on the designed output 
  * @param  HRTIMx: pointer to HRTIMx peripheral
  * @param  TimerIdx: Timer index
  *                   This parameter can be one of the following values:
  *                   @arg 0x0 to 0x4 for timers A to E 
  * @param  OnePulseChannel: Timer output
  *                    This parameter can be one of the following values:
  *                    @arg HRTIM_OUTPUT_TA1: Timer A - Output 1
  *                    @arg HRTIM_OUTPUT_TA2: Timer A - Output 2
  *                    @arg HRTIM_OUTPUT_TB1: Timer B - Output 1
  *                    @arg HRTIM_OUTPUT_TB2: Timer B - Output 2
  *                    @arg HRTIM_OUTPUT_TC1: Timer C - Output 1
  *                    @arg HRTIM_OUTPUT_TC2: Timer C - Output 2
  *                    @arg HRTIM_OUTPUT_TD1: Timer D - Output 1
  *                    @arg HRTIM_OUTPUT_TD2: Timer D - Output 2
  *                    @arg HRTIM_OUTPUT_TE1: Timer E - Output 1
  *                    @arg HRTIM_OUTPUT_TE2: Timer E - Output 2
  * @retval None
  */
void HRTIM_SimpleOnePulseStart(HRTIM_TypeDef * HRTIMx,
                                                uint32_t TimerIdx,
                                                uint32_t OnePulseChannel)
{
   /* Check the parameters */
  assert_param(IS_HRTIM_TIMER_OUTPUT(TimerIdx, OnePulseChannel));
  
  /* Enable the timer output */
  HRTIMx->HRTIM_COMMON.OENR |= OnePulseChannel;
    
  /* Enable the timer counter */
  __HRTIM_ENABLE(HRTIMx, TimerIdxToTimerId[TimerIdx]);
}

/**
  * @brief  Disables the basic one pulse signal generation on the designed output 
  * @param  HRTIMx: pointer to HRTIMx peripheral
  * @param  TimerIdx: Timer index
  *                   This parameter can be one of the following values:
  *                   @arg 0x0 to 0x4 for timers A to E 
  * @param  OnePulseChannel: Timer output
  *                    This parameter can be one of the following values:
  *                    @arg HRTIM_OUTPUT_TA1: Timer A - Output 1
  *                    @arg HRTIM_OUTPUT_TA2: Timer A - Output 2
  *                    @arg HRTIM_OUTPUT_TB1: Timer B - Output 1
  *                    @arg HRTIM_OUTPUT_TB2: Timer B - Output 2
  *                    @arg HRTIM_OUTPUT_TC1: Timer C - Output 1
  *                    @arg HRTIM_OUTPUT_TC2: Timer C - Output 2
  *                    @arg HRTIM_OUTPUT_TD1: Timer D - Output 1
  *                    @arg HRTIM_OUTPUT_TD2: Timer D - Output 2
  *                    @arg HRTIM_OUTPUT_TE1: Timer E - Output 1
  *                    @arg HRTIM_OUTPUT_TE2: Timer E - Output 2
  * @retval None
  */
void HRTIM_SimpleOnePulseStop(HRTIM_TypeDef * HRTIMx,
                                              uint32_t TimerIdx,
                                              uint32_t OnePulseChannel)
{
   /* Check the parameters */
  assert_param(IS_HRTIM_TIMER_OUTPUT(TimerIdx, OnePulseChannel));
   
  /* Disable the timer output */
  HRTIMx->HRTIM_COMMON.DISR |= OnePulseChannel;
  
  /* Disable the timer counter */
  __HRTIM_DISABLE(HRTIMx, TimerIdxToTimerId[TimerIdx]);
}

/**
  * @brief  Starts the counter of the designated timer(s) operating in waveform mode
  *         Timers can be combined (ORed) to allow for simultaneous counter start
  * @param  HRTIMx: pointer to HRTIMx peripheral
  * @param  TimersToStart: Timer counter(s) to start
  *                   This parameter can be any combination of the following values:
  *                   @arg HRTIM_TIMERID_MASTER 
  *                   @arg HRTIM_TIMERID_TIMER_A 
  *                   @arg HRTIM_TIMERID_TIMER_B 
  *                   @arg HRTIM_TIMERID_TIMER_C 
  *                   @arg HRTIM_TIMERID_TIMER_D 
  *                   @arg HRTIM_TIMERID_TIMER_E 
  * @retval None
  */
void HRTIM_WaveformCounterStart(HRTIM_TypeDef * HRTIMx,
                                                 uint32_t TimersToStart)
{ 
   /* Enable timer(s) counter */
   HRTIMx->HRTIM_MASTER.MCR |= TimersToStart;
}

/**
  * @brief  Stops the counter of the designated timer(s) operating in waveform mode
  *         Timers can be combined (ORed) to allow for simultaneous counter stop
  * @param  HRTIMx: pointer to HRTIMx peripheral
  * @param  TimersToStop: Timer counter(s) to stop
  *                   This parameter can be any combination of the following values:
  *                   @arg HRTIM_TIMER_MASTER 
  *                   @arg HRTIM_TIMER_A 
  *                   @arg HRTIM_TIMER_B 
  *                   @arg HRTIM_TIMER_C 
  *                   @arg HRTIM_TIMER_D 
  *                   @arg HRTIM_TIMER_E 
  * @retval None
  */
void HRTIM_WaveformCounterStop(HRTIM_TypeDef * HRTIMx,
                                                uint32_t TimersToStop)
{
  /* Disable timer(s) counter */
  HRTIMx->HRTIM_MASTER.MCR &= ~TimersToStop;
}

/**
  * @brief  Enables the generation of the waveform signal on the designated output(s)
  *         Outputs can be combined (ORed) to allow for simultaneous output enabling
  * @param  HRTIMx: pointer to HRTIMx peripheral
  * @param  OutputsToStart: Timer output(s) to enable
  *                    This parameter can be any combination of the following values:
  *                    @arg HRTIM_OUTPUT_TA1: Timer A - Output 1
  *                    @arg HRTIM_OUTPUT_TA2: Timer A - Output 2
  *                    @arg HRTIM_OUTPUT_TB1: Timer B - Output 1
  *                    @arg HRTIM_OUTPUT_TB2: Timer B - Output 2
  *                    @arg HRTIM_OUTPUT_TC1: Timer C - Output 1
  *                    @arg HRTIM_OUTPUT_TC2: Timer C - Output 2
  *                    @arg HRTIM_OUTPUT_TD1: Timer D - Output 1
  *                    @arg HRTIM_OUTPUT_TD2: Timer D - Output 2
  *                    @arg HRTIM_OUTPUT_TE1: Timer E - Output 1
  *                    @arg HRTIM_OUTPUT_TE2: Timer E - Output 2
  * @retval None
  */
void HRTIM_WaveformOutputStart(HRTIM_TypeDef * HRTIMx,
                                                uint32_t OutputsToStart)
{
  /* Enable the HRTIM outputs */
  HRTIMx->HRTIM_COMMON.OENR = OutputsToStart;
}

/**
  * @brief  Disables the generation of the waveform signal on the designated output(s)
  *         Outputs can be combined (ORed) to allow for simultaneous output disabling
  * @param  HRTIMx: pointer to HRTIMx peripheral
  * @param  OutputsToStop: Timer output(s) to disable
  *                    This parameter can be any combination of the following values:
  *                    @arg HRTIM_OUTPUT_TA1: Timer A - Output 1
  *                    @arg HRTIM_OUTPUT_TA2: Timer A - Output 2
  *                    @arg HRTIM_OUTPUT_TB1: Timer B - Output 1
  *                    @arg HRTIM_OUTPUT_TB2: Timer B - Output 2
  *                    @arg HRTIM_OUTPUT_TC1: Timer C - Output 1
  *                    @arg HRTIM_OUTPUT_TC2: Timer C - Output 2
  *                    @arg HRTIM_OUTPUT_TD1: Timer D - Output 1
  *                    @arg HRTIM_OUTPUT_TD2: Timer D - Output 2
  *                    @arg HRTIM_OUTPUT_TE1: Timer E - Output 1
  *                    @arg HRTIM_OUTPUT_TE2: Timer E - Output 2
  * @retval None
  */
void HRTIM_WaveformOutputStop(HRTIM_TypeDef * HRTIMx,
                                               uint32_t OutputsToStop)
{
  /* Disable the HRTIM outputs */
  HRTIMx->HRTIM_COMMON.DISR = OutputsToStop;
}

/**
  * @brief  Enables or disables the Master and slaves interrupt request
  * @param  HRTIMx: pointer to HRTIMx peripheral
  * @param  TimerIdx: Timer index
  *                   This parameter can be one of the following values:
  *                   @arg 0x0 to 0x4 for timers A to E 
  * @param  HRTIM_IT: specifies the HRTIM interrupts sources to be enabled or disabled.
  *          This parameter can be any combination of the following values:
  *            @arg HRTIM_MASTER_IT_MCMP1: Master compare 1 interrupt source
  *            @arg HRTIM_MASTER_IT_MCMP2: Master compare 2 interrupt source
  *            @arg HRTIM_MASTER_IT_MCMP3: Master compare 3 interrupt Interrupt source
  *            @arg HRTIM_MASTER_IT_MCMP4: Master compare 4 Interrupt source
  *            @arg HRTIM_MASTER_IT_MREP: Master Repetition Interrupt source
  *            @arg HRTIM_MASTER_IT_SYNC: Synchronization input Interrupt source
  *            @arg HRTIM_MASTER_IT_MUPD: Master update Interrupt source
  *            @arg HRTIM_TIM_IT_CMP1: Timer compare 1 Interrupt source
  *            @arg HRTIM_TIM_IT_CMP2: Timer compare 2 Interrupt source
  *            @arg HRTIM_TIM_IT_CMP3: Timer compare 3 Interrupt source
  *            @arg HRTIM_TIM_IT_CMP4: Timer compare 4 Interrupt source
  *            @arg HRTIM_TIM_IT_REP: Timer repetition Interrupt source
  *            @arg HRTIM_TIM_IT_UPD: Timer update Interrupt source
  *            @arg HRTIM_TIM_IT_CPT1: Timer capture 1 Interrupt source
  *            @arg HRTIM_TIM_IT_CPT2: Timer capture 2 Interrupt source
  *            @arg HRTIM_TIM_IT_SET1: Timer output 1 set Interrupt source
  *            @arg HRTIM_TIM_IT_RST1: Timer output 1 reset Interrupt source
  *            @arg HRTIM_TIM_IT_SET2: Timer output 2 set Interrupt source
  *            @arg HRTIM_TIM_IT_RST2: Timer output 2 reset Interrupt source
  *            @arg HRTIM_TIM_IT_RST: Timer reset Interrupt source
  *            @arg HRTIM_TIM_IT_DLYPRT1: Timer delay protection Interrupt source
  * @param  NewState: new state of the TIM interrupts.
  *          This parameter can be: ENABLE or DISABLE.
  * @retval None
  */
void HRTIM_ITConfig(HRTIM_TypeDef * HRTIMx, uint32_t TimerIdx, uint32_t HRTIM_IT, FunctionalState NewState)
{
  if(TimerIdx != HRTIM_TIMERINDEX_MASTER)
  {  
    if(NewState != DISABLE)
    {
      HRTIMx->HRTIM_TIMERx[TimerIdx].TIMxDIER |= HRTIM_IT;
    }
    else
    {
      HRTIMx->HRTIM_TIMERx[TimerIdx].TIMxDIER &= ~HRTIM_IT;
    }
  }
  else  
  {
    if(NewState != DISABLE)
    {
      HRTIMx->HRTIM_MASTER.MDIER |= HRTIM_IT;
    }
    else
    {
      HRTIMx->HRTIM_MASTER.MDIER &= ~HRTIM_IT;
    }  
  }
}

/**
  * @brief  Enables or disables the common interrupt request
  * @param  HRTIMx: pointer to HRTIMx peripheral
  * @param  HRTIM_IT: specifies the HRTIM interrupts sources to be enabled or disabled.
  *          This parameter can be any combination of the following values:
  *            @arg HRTIM_IT_FLT1: Fault 1 interrupt source
  *            @arg HRTIM_IT_FLT2: Fault 2 interrupt source
  *            @arg HRTIM_IT_FLT3: Fault 3 interrupt Interrupt source
  *            @arg HRTIM_IT_FLT4: Fault 4 Interrupt source
  *            @arg HRTIM_IT_FLT5: Fault 5  Interrupt source
  *            @arg HRTIM_IT_SYSFLT: System Fault Interrupt source
  *            @arg HRTIM_IT_DLLRDY: DLL ready Interrupt source
  *            @arg HRTIM_IT_BMPER: Burst mode period Interrupt source
  * @param  NewState: new state of the TIM interrupts.
  *          This parameter can be: ENABLE or DISABLE.
  * @retval None
  */
void HRTIM_ITCommonConfig(HRTIM_TypeDef * HRTIMx, uint32_t HRTIM_CommonIT, FunctionalState NewState)
{
   if(NewState != DISABLE)
    {
      HRTIMx->HRTIM_COMMON.IER |= HRTIM_CommonIT;
    }
    else
    {
      HRTIMx->HRTIM_COMMON.IER &= ~HRTIM_CommonIT;
    }
}

/**
  * @brief  Clears the Master and slaves interrupt flags
  * @param  HRTIMx: pointer to HRTIMx peripheral
  * @param  TimerIdx: Timer index
  *                   This parameter can be one of the following values:
  *                   @arg 0x0 to 0x4 for timers A to E 
  * @param  HRTIM_FLAG: specifies the HRTIM flags sources to be cleared.
  *          This parameter can be any combination of the following values:
  *            @arg HRTIM_MASTER_FLAG_MCMP1: Master compare 1 interrupt flag
  *            @arg HRTIM_MASTER_FLAG_MCMP2: Master compare 2 interrupt flag
  *            @arg HRTIM_MASTER_FLAG_MCMP3: Master compare 3 interrupt Interrupt flag
  *            @arg HRTIM_MASTER_FLAG_MCMP4: Master compare 4 Interrupt flag
  *            @arg HRTIM_MASTER_FLAG_MREP: Master Repetition Interrupt flag
  *            @arg HRTIM_MASTER_FLAG_SYNC: Synchronization input Interrupt flag
  *            @arg HRTIM_MASTER_FLAG_MUPD: Master update Interrupt flag
  *            @arg HRTIM_TIM_FLAG_CMP1: Timer compare 1 Interrupt flag
  *            @arg HRTIM_TIM_FLAG_CMP2: Timer compare 2 Interrupt flag
  *            @arg HRTIM_TIM_FLAG_CMP3: Timer compare 3 Interrupt flag
  *            @arg HRTIM_TIM_FLAG_CMP4: Timer compare 4 Interrupt flag
  *            @arg HRTIM_TIM_FLAG_REP: Timer repetition Interrupt flag
  *            @arg HRTIM_TIM_FLAG_UPD: Timer update Interrupt flag
  *            @arg HRTIM_TIM_FLAG_CPT1: Timer capture 1 Interrupt flag
  *            @arg HRTIM_TIM_FLAG_CPT2: Timer capture 2 Interrupt flag
  *            @arg HRTIM_TIM_FLAG_SET1: Timer output 1 set Interrupt flag
  *            @arg HRTIM_TIM_FLAG_RST1: Timer output 1 reset Interrupt flag
  *            @arg HRTIM_TIM_FLAG_SET2: Timer output 2 set Interrupt flag
  *            @arg HRTIM_TIM_FLAG_RST2: Timer output 2 reset Interrupt flag
  *            @arg HRTIM_TIM_FLAG_RST: Timer reset Interrupt flag
  *            @arg HRTIM_TIM_FLAG_DLYPRT1: Timer delay protection Interrupt flag
  * @retval None
  */
void HRTIM_ClearFlag(HRTIM_TypeDef * HRTIMx, uint32_t TimerIdx, uint32_t HRTIM_FLAG)
{
  if(TimerIdx != HRTIM_TIMERINDEX_MASTER)
  {
    HRTIMx->HRTIM_MASTER.MICR |= HRTIM_FLAG;
  }
  else
  {
     HRTIMx->HRTIM_TIMERx[TimerIdx].TIMxICR |= HRTIM_FLAG;
  }  
}

/**
  * @brief  Clears the common interrupt flags
  * @param  HRTIMx: pointer to HRTIMx peripheral
  * @param  HRTIM_FLAG: specifies the HRTIM flags to be cleared.
  *          This parameter can be any combination of the following values:
  *            @arg HRTIM_FLAG_FLT1: Fault 1 interrupt flag
  *            @arg HRTIM_FLAG_FLT2: Fault 2 interrupt flag
  *            @arg HRTIM_FLAG_FLT3: Fault 3 interrupt Interrupt flag
  *            @arg HRTIM_FLAG_FLT4: Fault 4 Interrupt flag
  *            @arg HRTIM_FLAG_FLT5: Fault 5  Interrupt flag
  *            @arg HRTIM_FLAG_SYSFLT: System Fault Interrupt flag
  *            @arg HRTIM_FLAG_DLLRDY: DLL ready Interrupt flag
  *            @arg HRTIM_FLAG_BMPER: Burst mode period Interrupt flag
  * @retval None
  */
void HRTIM_ClearCommonFlag(HRTIM_TypeDef * HRTIMx, uint32_t HRTIM_CommonFLAG)
{
  HRTIMx->HRTIM_COMMON.ICR |= HRTIM_CommonFLAG;
}

/**
  * @brief  Clears the Master and slaves interrupt request pending bits
  * @param  HRTIMx: pointer to HRTIMx peripheral
  * @param  TimerIdx: Timer index
  *                   This parameter can be one of the following values:
  *                   @arg 0x0 to 0x4 for timers A to E 
  * @param  HRTIM_IT: specifies the HRTIM interrupts sources to be enabled or disabled.
  *          This parameter can be any combination of the following values:
  *            @arg HRTIM_MASTER_IT_MCMP1: Master compare 1 interrupt source
  *            @arg HRTIM_MASTER_IT_MCMP2: Master compare 2 interrupt source
  *            @arg HRTIM_MASTER_IT_MCMP3: Master compare 3 interrupt Interrupt source
  *            @arg HRTIM_MASTER_IT_MCMP4: Master compare 4 Interrupt source
  *            @arg HRTIM_MASTER_IT_MREP: Master Repetition Interrupt source
  *            @arg HRTIM_MASTER_IT_SYNC: Synchronization input Interrupt source
  *            @arg HRTIM_MASTER_IT_MUPD: Master update Interrupt source
  *            @arg HRTIM_TIM_IT_CMP1: Timer compare 1 Interrupt source
  *            @arg HRTIM_TIM_IT_CMP2: Timer compare 2 Interrupt source
  *            @arg HRTIM_TIM_IT_CMP3: Timer compare 3 Interrupt source
  *            @arg HRTIM_TIM_IT_CMP4: Timer compare 4 Interrupt source
  *            @arg HRTIM_TIM_IT_REP: Timer repetition Interrupt source
  *            @arg HRTIM_TIM_IT_UPD: Timer update Interrupt source
  *            @arg HRTIM_TIM_IT_CPT1: Timer capture 1 Interrupt source
  *            @arg HRTIM_TIM_IT_CPT2: Timer capture 2 Interrupt source
  *            @arg HRTIM_TIM_IT_SET1: Timer output 1 set Interrupt source
  *            @arg HRTIM_TIM_IT_RST1: Timer output 1 reset Interrupt source
  *            @arg HRTIM_TIM_IT_SET2: Timer output 2 set Interrupt source
  *            @arg HRTIM_TIM_IT_RST2: Timer output 2 reset Interrupt source
  *            @arg HRTIM_TIM_IT_RST: Timer reset Interrupt source
  *            @arg HRTIM_TIM_IT_DLYPRT: Timer delay protection Interrupt source
  * @retval None
  */
void HRTIM_ClearITPendingBit(HRTIM_TypeDef * HRTIMx, uint32_t TimerIdx, uint32_t HRTIM_IT)
{
  if(TimerIdx != HRTIM_TIMERINDEX_MASTER)
  {
    HRTIMx->HRTIM_TIMERx[TimerIdx].TIMxICR |= HRTIM_IT;
  }
  else 
  {   
    HRTIMx->HRTIM_MASTER.MICR |= HRTIM_IT;
  }
}

/**
  * @brief  Clears the common interrupt pending bits
  * @param  HRTIMx: pointer to HRTIMx peripheral
  * @param  HRTIM_IT: specifies the HRTIM interrupts sources to be cleared.
  *          This parameter can be any combination of the following values:
  *            @arg HRTIM_IT_FLT1: Fault 1 interrupt source
  *            @arg HRTIM_IT_FLT2: Fault 2 interrupt source
  *            @arg HRTIM_IT_FLT3: Fault 3 interrupt Interrupt source
  *            @arg HRTIM_IT_FLT4: Fault 4 Interrupt source
  *            @arg HRTIM_IT_FLT5: Fault 5  Interrupt source
  *            @arg HRTIM_IT_SYSFLT: System Fault Interrupt source
  *            @arg HRTIM_IT_DLLRDY: DLL ready Interrupt source
  *            @arg HRTIM_IT_BMPER: Burst mode period Interrupt source
  * @retval None
  */
void HRTIM_ClearCommonITPendingBit(HRTIM_TypeDef * HRTIMx, uint32_t HRTIM_CommonIT)
{
  HRTIMx->HRTIM_COMMON.ICR |= HRTIM_CommonIT;
}


/**
  * @brief  Checks whether the specified HRTIM flag is set or not.
  * @param  HRTIMx: pointer to HRTIMx peripheral
  * @param  TimerIdx: Timer index
  *                   This parameter can be one of the following values:
  *                   @arg 0x0 to 0x4 for timers A to E 
  * @param  HRTIM_FLAG: specifies the HRTIM flags to check.
  *          This parameter can be any combination of the following values:
  *            @arg HRTIM_MASTER_FLAG_MCMP1: Master compare 1 interrupt flag
  *            @arg HRTIM_MASTER_FLAG_MCMP2: Master compare 2 interrupt flag
  *            @arg HRTIM_MASTER_FLAG_MCMP3: Master compare 3 interrupt Interrupt flag
  *            @arg HRTIM_MASTER_FLAG_MCMP4: Master compare 4 Interrupt flag
  *            @arg HRTIM_MASTER_FLAG_MREP: Master Repetition Interrupt flag
  *            @arg HRTIM_MASTER_FLAG_SYNC: Synchronization input Interrupt flag
  *            @arg HRTIM_MASTER_FLAG_MUPD: Master update Interrupt flag
  *            @arg HRTIM_TIM_FLAG_CMP1: Timer compare 1 Interrupt flag
  *            @arg HRTIM_TIM_FLAG_CMP2: Timer compare 2 Interrupt flag
  *            @arg HRTIM_TIM_FLAG_CMP3: Timer compare 3 Interrupt flag
  *            @arg HRTIM_TIM_FLAG_CMP4: Timer compare 4 Interrupt flag
  *            @arg HRTIM_TIM_FLAG_REP: Timer repetition Interrupt flag
  *            @arg HRTIM_TIM_FLAG_UPD: Timer update Interrupt flag
  *            @arg HRTIM_TIM_FLAG_CPT1: Timer capture 1 Interrupt flag
  *            @arg HRTIM_TIM_FLAG_CPT2: Timer capture 2 Interrupt flag
  *            @arg HRTIM_TIM_FLAG_SET1: Timer output 1 set Interrupt flag
  *            @arg HRTIM_TIM_FLAG_RST1: Timer output 1 reset Interrupt flag
  *            @arg HRTIM_TIM_FLAG_SET2: Timer output 2 set Interrupt flag
  *            @arg HRTIM_TIM_FLAG_RST2: Timer output 2 reset Interrupt flag
  *            @arg HRTIM_TIM_FLAG_RST: Timer reset Interrupt flag
  *            @arg HRTIM_TIM_FLAG_DLYPRT: Timer delay protection Interrupt flag
  * @retval The new state of HRTIM_FLAG (SET or RESET).
  */
FlagStatus HRTIM_GetFlagStatus(HRTIM_TypeDef * HRTIMx, uint32_t TimerIdx, uint32_t HRTIM_FLAG)
{
  FlagStatus bitstatus = RESET;  

  if(TimerIdx != HRTIM_TIMERINDEX_MASTER)
  {  
    if ((HRTIMx->HRTIM_TIMERx[TimerIdx].TIMxISR & HRTIM_FLAG) != RESET)
    {
      bitstatus = SET;
    }
    else
    {
      bitstatus = RESET;
    }
  }
  else
  {
    if ((HRTIMx->HRTIM_MASTER.MISR & HRTIM_FLAG) != RESET)
    {
      bitstatus = SET;
    }
    else
    {
      bitstatus = RESET;
    }
  }  
  return bitstatus;
}

/**
  * @brief  Checks whether the specified HRTIM common flag is set or not.
  * @param  HRTIMx: pointer to HRTIMx peripheral
  * @param  HRTIM_FLAG: specifies the HRTIM flags to check.
  *          This parameter can be any combination of the following values:
  *            @arg HRTIM_FLAG_FLT1: Fault 1 interrupt flag
  *            @arg HRTIM_FLAG_FLT2: Fault 2 interrupt flag
  *            @arg HRTIM_FLAG_FLT3: Fault 3 interrupt Interrupt flag
  *            @arg HRTIM_FLAG_FLT4: Fault 4 Interrupt flag
  *            @arg HRTIM_FLAG_FLT5: Fault 5  Interrupt flag
  *            @arg HRTIM_FLAG_SYSFLT: System Fault Interrupt flag
  *            @arg HRTIM_FLAG_DLLRDY: DLL ready Interrupt flag
  *            @arg HRTIM_FLAG_BMPER: Burst mode period Interrupt flag
  * @retval The new state of HRTIM_FLAG (SET or RESET).
  */
FlagStatus HRTIM_GetCommonFlagStatus(HRTIM_TypeDef * HRTIMx, uint32_t HRTIM_CommonFLAG)
{
  FlagStatus bitstatus = RESET;  

  if((HRTIMx->HRTIM_COMMON.ISR & HRTIM_CommonFLAG) != RESET)
    {
      bitstatus = SET;
    }
    else
    {
      bitstatus = RESET;
    }
  return bitstatus;
}
                                       
/**
  * @brief  Checks whether the specified HRTIM interrupt has occurred or not.
  * @param  HRTIMx: pointer to HRTIMx peripheral
  * @param  TimerIdx: Timer index
  *                   This parameter can be one of the following values:
  *                   @arg 0x0 to 0x4 for timers A to E 
  * @param  HRTIM_IT: specifies the HRTIM flags sources to be cleared.
  *          This parameter can be any combination of the following values:
  *            @arg HRTIM_MASTER_IT_MCMP1: Master compare 1 interrupt 
  *            @arg HRTIM_MASTER_IT_MCMP2: Master compare 2 interrupt 
  *            @arg HRTIM_MASTER_IT_MCMP3: Master compare 3 interrupt Interrupt 
  *            @arg HRTIM_MASTER_IT_MCMP4: Master compare 4 Interrupt 
  *            @arg HRTIM_MASTER_IT_MREP: Master Repetition Interrupt 
  *            @arg HRTIM_MASTER_IT_SYNC: Synchronization input Interrupt 
  *            @arg HRTIM_MASTER_IT_MUPD: Master update Interrupt 
  *            @arg HRTIM_TIM_IT_CMP1: Timer compare 1 Interrupt 
  *            @arg HRTIM_TIM_IT_CMP2: Timer compare 2 Interrupt 
  *            @arg HRTIM_TIM_IT_CMP3: Timer compare 3 Interrupt 
  *            @arg HRTIM_TIM_IT_CMP4: Timer compare 4 Interrupt 
  *            @arg HRTIM_TIM_IT_REP: Timer repetition Interrupt 
  *            @arg HRTIM_TIM_IT_UPD: Timer update Interrupt 
  *            @arg HRTIM_TIM_IT_CPT1: Timer capture 1 Interrupt 
  *            @arg HRTIM_TIM_IT_CPT2: Timer capture 2 Interrupt 
  *            @arg HRTIM_TIM_IT_SET1: Timer output 1 set Interrupt 
  *            @arg HRTIM_TIM_IT_RST1: Timer output 1 reset Interrupt 
  *            @arg HRTIM_TIM_IT_SET2: Timer output 2 set Interrupt 
  *            @arg HRTIM_TIM_IT_RST2: Timer output 2 reset Interrupt 
  *            @arg HRTIM_TIM_IT_RST: Timer reset Interrupt 
  *            @arg HRTIM_TIM_IT_DLYPRT: Timer delay protection Interrupt 
  * @retval The new state of the HRTIM_IT(SET or RESET).
  */
ITStatus HRTIM_GetITStatus(HRTIM_TypeDef * HRTIMx, uint32_t TimerIdx, uint32_t HRTIM_IT)
{
  ITStatus bitstatus = RESET;  
  uint16_t itstatus = 0x0, itenable = 0x0;

  if(TimerIdx != HRTIM_TIMERINDEX_MASTER)
  {  
    itstatus = HRTIMx->HRTIM_TIMERx[TimerIdx].TIMxISR & HRTIM_IT;
  
    itenable = HRTIMx->HRTIM_TIMERx[TimerIdx].TIMxDIER & HRTIM_IT;
    if ((itstatus != (uint16_t)RESET) && (itenable != (uint16_t)RESET))
    {
      bitstatus = SET;
    }
    else
    {
      bitstatus = RESET;
    }
  }
  else
  {
    itstatus = HRTIMx->HRTIM_MASTER.MISR & HRTIM_IT;
  
    itenable = HRTIMx->HRTIM_MASTER.MDIER & HRTIM_IT;
    if ((itstatus != (uint16_t)RESET) && (itenable != (uint16_t)RESET))
    {
      bitstatus = SET;
    }
    else
    {
      bitstatus = RESET;
    }
  }  
  return bitstatus;
}

/**
  * @brief  Checks whether the specified HRTIM common interrupt has occurred or not.
  * @param  HRTIMx: pointer to HRTIMx peripheral
  * @param  HRTIM_IT: specifies the HRTIM interrupt source to check.
  *          This parameter can be any combination of the following values:
  *            @arg HRTIM_IT_FLT1: Fault 1 interrupt 
  *            @arg HRTIM_IT_FLT2: Fault 2 interrupt 
  *            @arg HRTIM_IT_FLT3: Fault 3 interrupt Interrupt 
  *            @arg HRTIM_IT_FLT4: Fault 4 Interrupt 
  *            @arg HRTIM_IT_FLT5: Fault 5  Interrupt 
  *            @arg HRTIM_IT_SYSFLT: System Fault Interrupt 
  *            @arg HRTIM_IT_DLLRDY: DLL ready Interrupt flag
  *            @arg HRTIM_IT_BMPER: Burst mode period Interrupt 
  * @retval The new state of HRTIM_FLAG (SET or RESET).
  */
ITStatus HRTIM_GetCommonITStatus(HRTIM_TypeDef * HRTIMx, uint32_t HRTIM_CommonIT)
{
  ITStatus bitstatus = RESET;  
  uint16_t itstatus = 0x0, itenable = 0x0;
 
  itstatus = HRTIMx->HRTIM_COMMON.ISR & HRTIM_CommonIT; 
  itenable = HRTIMx->HRTIM_COMMON.IER & HRTIM_CommonIT;
  
  if ((itstatus != (uint16_t)RESET) && (itenable != (uint16_t)RESET))
  {
    bitstatus = SET;
  }
  else
  {
    bitstatus = RESET;
  }

  return bitstatus;
}

/**
  * @brief  Enables or disables the HRTIMx's DMA Requests.
  * @param  HRTIMx: pointer to HRTIMx peripheral
  * @param  TimerIdx: Timer index
  *                   This parameter can be one of the following values:
  *                   @arg 0x0 to 0x4 for timers A to E 
  * @param  HRTIM_DMA: specifies the DMA Request sources.
  *          This parameter can be any combination of the following values:
  *            @arg HRTIM_MASTER_DMA_MCMP1: Master compare 1 DMA request source
  *            @arg HRTIM_MASTER_DMA_MCMP2: Master compare 2 DMA request source
  *            @arg HRTIM_MASTER_DMA_MCMP3: Master compare 3 DMA request source
  *            @arg HRTIM_MASTER_DMA_MCMP4: Master compare 4 DMA request source
  *            @arg HRTIM_MASTER_DMA_MREP: Master Repetition DMA request source
  *            @arg HRTIM_MASTER_DMA_SYNC: Synchronization input DMA request source
  *            @arg HRTIM_MASTER_DMA_MUPD:Master update DMA request source
  *            @arg HRTIM_TIM_DMA_CMP1: Timer compare 1 DMA request source 
  *            @arg HRTIM_TIM_DMA_CMP2: Timer compare 2 DMA request source 
  *            @arg HRTIM_TIM_DMA_CMP3: Timer compare 3 DMA request source 
  *            @arg HRTIM_TIM_DMA_CMP4: Timer compare 4 DMA request source 
  *            @arg HRTIM_TIM_DMA_REP: Timer repetition DMA request source 
  *            @arg HRTIM_TIM_DMA_UPD: Timer update DMA request source 
  *            @arg HRTIM_TIM_DMA_CPT1: Timer capture 1 DMA request source 
  *            @arg HRTIM_TIM_DMA_CPT2: Timer capture 2 DMA request source 
  *            @arg HRTIM_TIM_DMA_SET1: Timer output 1 set DMA request source 
  *            @arg HRTIM_TIM_DMA_RST1: Timer output 1 reset DMA request source 
  *            @arg HRTIM_TIM_DMA_SET2: Timer output 2 set DMA request source 
  *            @arg HRTIM_TIM_DMA_RST2: Timer output 2 reset DMA request source 
  *            @arg HRTIM_TIM_DMA_RST: Timer reset DMA request source 
  *            @arg HRTIM_TIM_DMA_DLYPRT: Timer delay protection DMA request source 
  * @param  NewState: new state of the DMA Request sources.
  *          This parameter can be: ENABLE or DISABLE.
  * @retval None
  */
void HRTIM_DMACmd(HRTIM_TypeDef* HRTIMx, uint32_t TimerIdx, uint32_t HRTIM_DMA, FunctionalState NewState)
{
  if(TimerIdx != HRTIM_TIMERINDEX_MASTER)
  { 
     if(NewState != DISABLE)
     {
       HRTIMx->HRTIM_TIMERx[TimerIdx].TIMxDIER |= HRTIM_DMA;
     }
     else
     {
       HRTIMx->HRTIM_TIMERx[TimerIdx].TIMxDIER &= ~HRTIM_DMA;
     }
  }
  else
  {
     if(NewState != DISABLE)
     {
       HRTIMx->HRTIM_MASTER.MDIER |= HRTIM_DMA;
     }
     else
     {
       HRTIMx->HRTIM_MASTER.MDIER &= ~HRTIM_DMA;
     }
  }  
}

/**
  * @}
  */

/** @defgroup HRTIM_Group3 Peripheral Control methods 
 *  @brief   management functions 
 *
@verbatim   
 ===============================================================================
                      ##### Peripheral Control methods #####
 ===============================================================================  
    [..]
    This subsection provides a set of functions allowing to control the HRTIMx data 
    transfers.

@endverbatim
  * @{
  */

/**
  * @brief  Configures an output in basic output compare mode 
  * @param  HRTIMx: pointer to HRTIMx peripheral
  * @param  TimerIdx: Timer index
  *                   This parameter can be one of the following values:
  *                   @arg 0x0 to 0x4 for timers A to E 
  * @param  OCChannel: Timer output
  *                    This parameter can be one of the following values:
  *                    @arg HRTIM_OUTPUT_TA1: Timer A - Output 1
  *                    @arg HRTIM_OUTPUT_TA2: Timer A - Output 2
  *                    @arg HRTIM_OUTPUT_TB1: Timer B - Output 1
  *                    @arg HRTIM_OUTPUT_TB2: Timer B - Output 2
  *                    @arg HRTIM_OUTPUT_TC1: Timer C - Output 1
  *                    @arg HRTIM_OUTPUT_TC2: Timer C - Output 2
  *                    @arg HRTIM_OUTPUT_TD1: Timer D - Output 1
  *                    @arg HRTIM_OUTPUT_TD2: Timer D - Output 2
  *                    @arg HRTIM_OUTPUT_TE1: Timer E - Output 1
  *                    @arg HRTIM_OUTPUT_TE2: Timer E - Output 2 
  * @param  pBasicOCChannelCfg: pointer to the basic output compare output configuration structure
  * @note When the timer operates in basic output compare mode:
  *         Output 1 is implicitely controled by the compare unit 1
  *         Output 2 is implicitely controled by the compare unit 2
  *       Output Set/Reset crossbar is set according to the selected output compare mode:
  *         Toggle: SETxyR = RSTxyR = CMPy
  *         Active: SETxyR = CMPy, RSTxyR = 0
  *         Inactive: SETxy =0, RSTxy = CMPy
  * @retval None
  */
void HRTIM_SimpleOCChannelConfig(HRTIM_TypeDef * HRTIM_,
                                                 uint32_t TimerIdx,
                                                 uint32_t OCChannel,
                                                 HRTIM_BasicOCChannelCfgTypeDef* pBasicOCChannelCfg)
{
  uint32_t CompareUnit = HRTIM_COMPAREUNIT_1;
  HRTIM_CompareCfgTypeDef CompareCfg;
  HRTIM_OutputCfgTypeDef OutputCfg;
  
  /* Check parameters */
  assert_param(IS_HRTIM_TIMER_OUTPUT(TimerIdx, OCChannel));
  assert_param(IS_HRTIM_BASICOCMODE(pBasicOCChannelCfg->Mode));
  assert_param(IS_HRTIM_OUTPUTPOLARITY(pBasicOCChannelCfg->Polarity));
  assert_param(IS_HRTIM_OUTPUTIDLESTATE(pBasicOCChannelCfg->IdleState));
    
  /* Configure timer compare unit */  
  switch (OCChannel)
  {
    case HRTIM_OUTPUT_TA1:
    case HRTIM_OUTPUT_TB1:
    case HRTIM_OUTPUT_TC1:
    case HRTIM_OUTPUT_TD1:
    case HRTIM_OUTPUT_TE1:
    {
      CompareUnit = HRTIM_COMPAREUNIT_1;
    }
    break;
    case HRTIM_OUTPUT_TA2:
    case HRTIM_OUTPUT_TB2:
    case HRTIM_OUTPUT_TC2:
    case HRTIM_OUTPUT_TD2:
    case HRTIM_OUTPUT_TE2:
    {
      CompareUnit = HRTIM_COMPAREUNIT_2;
    }
    break;
    default:
    break;
  }
  
  CompareCfg.CompareValue = pBasicOCChannelCfg->Pulse;
  CompareCfg.AutoDelayedMode = HRTIM_AUTODELAYEDMODE_REGULAR;
  CompareCfg.AutoDelayedTimeout = 0;
  
  HRTIM_CompareUnitConfig(HRTIM_,
                          TimerIdx,
                          CompareUnit,
                          &CompareCfg);
  
  /* Configure timer output */
  OutputCfg.Polarity = pBasicOCChannelCfg->Polarity;
  OutputCfg.IdleState = pBasicOCChannelCfg->IdleState;
  OutputCfg.FaultState = HRTIM_OUTPUTFAULTSTATE_NONE;
  OutputCfg.IdleMode = HRTIM_OUTPUTIDLEMODE_NONE;
  OutputCfg.ChopperModeEnable = HRTIM_OUTPUTCHOPPERMODE_DISABLED;
  OutputCfg.BurstModeEntryDelayed = HRTIM_OUTPUTBURSTMODEENTRY_REGULAR;
  
  switch (pBasicOCChannelCfg->Mode)
  {
    case HRTIM_BASICOCMODE_TOGGLE:
    {
      if (CompareUnit == HRTIM_COMPAREUNIT_1)
      {
        OutputCfg.SetSource = HRTIM_OUTPUTSET_TIMCMP1;
      }
      else
      {
        OutputCfg.SetSource = HRTIM_OUTPUTSET_TIMCMP2;
      }
      OutputCfg.ResetSource = OutputCfg.SetSource;
    }
    break;
    case HRTIM_BASICOCMODE_ACTIVE:
    {
      if (CompareUnit == HRTIM_COMPAREUNIT_1)
      {
        OutputCfg.SetSource = HRTIM_OUTPUTSET_TIMCMP1;
      }
      else
      {
        OutputCfg.SetSource = HRTIM_OUTPUTSET_TIMCMP2;
      }
      OutputCfg.ResetSource = HRTIM_OUTPUTRESET_NONE;
    }
    break;
    case HRTIM_BASICOCMODE_INACTIVE:
    {
      if (CompareUnit == HRTIM_COMPAREUNIT_1)
      {
        OutputCfg.ResetSource = HRTIM_OUTPUTRESET_TIMCMP1;
      }
      else
      {
        OutputCfg.ResetSource = HRTIM_OUTPUTRESET_TIMCMP2;
      }
      OutputCfg.SetSource = HRTIM_OUTPUTSET_NONE;
    }
    break;
    default:
    break;  
  }
  
  HRTIM_OutputConfig(HRTIM_, TimerIdx, OCChannel, &OutputCfg);   
}

/**
  * @brief  Configures an output in basic PWM mode 
  * @param  HRTIMx: pointer to HRTIMx peripheral
  * @param  TimerIdx: Timer index
  *                   This parameter can be one of the following values:
  *                   @arg 0x0 to 0x4 for timers A to E 
  * @param  PWMChannel: Timer output
  *                    This parameter can be one of the following values:
  *                    @arg HRTIM_OUTPUT_TA1: Timer A - Output 1
  *                    @arg HRTIM_OUTPUT_TA2: Timer A - Output 2
  *                    @arg HRTIM_OUTPUT_TB1: Timer B - Output 1
  *                    @arg HRTIM_OUTPUT_TB2: Timer B - Output 2
  *                    @arg HRTIM_OUTPUT_TC1: Timer C - Output 1
  *                    @arg HRTIM_OUTPUT_TC2: Timer C - Output 2
  *                    @arg HRTIM_OUTPUT_TD1: Timer D - Output 1
  *                    @arg HRTIM_OUTPUT_TD2: Timer D - Output 2
  *                    @arg HRTIM_OUTPUT_TE1: Timer E - Output 1
  *                    @arg HRTIM_OUTPUT_TE2: Timer E - Output 2 
  * @param  pBasicPWMChannelCfg: pointer to the basic PWM output configuration structure
  * @note When the timer operates in basic PWM output mode:
  *         Output 1 is implicitly controled by the compare unit 1
  *         Output 2 is implicitly controled by the compare unit 2
  *         Output Set/Reset crossbar is set as follows:
  *         Output 1: SETx1R = CMP1, RSTx1R = PER
  *         Output 2: SETx2R = CMP2, RST2R = PER
  * @retval None
  */
void HRTIM_SimplePWMChannelConfig(HRTIM_TypeDef * HRTIM_,
                                                  uint32_t TimerIdx,
                                                  uint32_t PWMChannel,
                                                  HRTIM_BasicPWMChannelCfgTypeDef* pBasicPWMChannelCfg)
{
  uint32_t CompareUnit = HRTIM_COMPAREUNIT_1;
  HRTIM_CompareCfgTypeDef CompareCfg;
  HRTIM_OutputCfgTypeDef OutputCfg;

  /* Check parameters */
  assert_param(IS_HRTIM_TIMER_OUTPUT(TimerIdx, PWMChannel));
  assert_param(IS_HRTIM_OUTPUTPOLARITY(pBasicPWMChannelCfg->Polarity));
  assert_param(IS_HRTIM_OUTPUTIDLESTATE(pBasicPWMChannelCfg->IdleState));

  /* Configure timer compare unit */  
  switch (PWMChannel)
  {
    case HRTIM_OUTPUT_TA1:
    case HRTIM_OUTPUT_TB1:
    case HRTIM_OUTPUT_TC1:
    case HRTIM_OUTPUT_TD1:
    case HRTIM_OUTPUT_TE1:
    {
      CompareUnit = HRTIM_COMPAREUNIT_1;
    }
    break;
    case HRTIM_OUTPUT_TA2:
    case HRTIM_OUTPUT_TB2:
    case HRTIM_OUTPUT_TC2:
    case HRTIM_OUTPUT_TD2:
    case HRTIM_OUTPUT_TE2:
    {
      CompareUnit = HRTIM_COMPAREUNIT_2;
    }
    break;
    default:
    break;  
  }
  
  CompareCfg.CompareValue = pBasicPWMChannelCfg->Pulse;
  CompareCfg.AutoDelayedMode = HRTIM_AUTODELAYEDMODE_REGULAR;
  CompareCfg.AutoDelayedTimeout = 0;
  
  HRTIM_CompareUnitConfig(HRTIM_,
                          TimerIdx,
                          CompareUnit,
                          &CompareCfg);
  
  /* Configure timer output */
  OutputCfg.Polarity = pBasicPWMChannelCfg->Polarity;
  OutputCfg.IdleState = pBasicPWMChannelCfg->IdleState;
  OutputCfg.FaultState = HRTIM_OUTPUTFAULTSTATE_NONE;
  OutputCfg.IdleMode = HRTIM_OUTPUTIDLEMODE_NONE;
  OutputCfg.ChopperModeEnable = HRTIM_OUTPUTCHOPPERMODE_DISABLED;
  OutputCfg.BurstModeEntryDelayed = HRTIM_OUTPUTBURSTMODEENTRY_REGULAR;
  
  if (CompareUnit == HRTIM_COMPAREUNIT_1)
  {
    OutputCfg.SetSource = HRTIM_OUTPUTSET_TIMCMP1;
  }
  else
  {
    OutputCfg.SetSource = HRTIM_OUTPUTSET_TIMCMP2;
  }
  OutputCfg.ResetSource = HRTIM_OUTPUTSET_TIMPER;
  
  HRTIM_OutputConfig(HRTIM_, TimerIdx, PWMChannel, &OutputCfg);  
}

/**
  * @brief  Configures a basic capture 
  * @param  HRTIMx: pointer to HRTIMx peripheral
  * @param  TimerIdx: Timer index
  *                   This parameter can be one of the following values:
  *                   @arg 0x0 to 0x4 for timers A to E 
  * @param  CaptureChannel: Capture unit
  *                    This parameter can be one of the following values: 
  *                    @arg HRTIM_CAPTUREUNIT_1: Capture unit 1
  *                    @arg HRTIM_CAPTUREUNIT_2: Capture unit 2
  * @param  pBasicCaptureChannelCfg: pointer to the basic capture configuration structure
  * @note When the timer operates in basic capture mode the capture is triggered
  *       by the designated external event and GPIO input is implicitly used as event source.
  *       The cature can be triggered by a rising edge, a falling edge or both
  *       edges on event channel.
  * @retval None
  */
void HRTIM_SimpleCaptureChannelConfig(HRTIM_TypeDef * HRTIMx,
                                                      uint32_t TimerIdx,
                                                      uint32_t CaptureChannel,
                                                      HRTIM_BasicCaptureChannelCfgTypeDef* pBasicCaptureChannelCfg)
{
  HRTIM_EventCfgTypeDef EventCfg;
  
  /* Check parameters */
  assert_param(IS_HRTIM_TIMING_UNIT(TimerIdx));
  assert_param(IS_HRTIM_CAPTUREUNIT(CaptureChannel));
  assert_param(IS_HRTIM_EVENT(pBasicCaptureChannelCfg->Event));
  assert_param(IS_HRTIM_EVENTPOLARITY(pBasicCaptureChannelCfg->EventPolarity));
  assert_param(IS_HRTIM_EVENTSENSITIVITY(pBasicCaptureChannelCfg->EventSensitivity));
  assert_param(IS_HRTIM_EVENTFILTER(pBasicCaptureChannelCfg->EventFilter));
  
  /* Configure external event channel */
  EventCfg.FastMode = HRTIM_EVENTFASTMODE_DISABLE;
  EventCfg.Filter = pBasicCaptureChannelCfg->EventFilter;
  EventCfg.Polarity = pBasicCaptureChannelCfg->EventPolarity;
  EventCfg.Sensitivity = pBasicCaptureChannelCfg->EventSensitivity;
  EventCfg.Source = HRTIM_EVENTSRC_1;
    
  HRTIM_ExternalEventConfig(HRTIMx,
                    pBasicCaptureChannelCfg->Event,
                    &EventCfg);

  /* Memorize capture trigger (will be configured when the capture is started */  
  HRTIM_CaptureUnitConfig(HRTIMx,
                          TimerIdx,
                          CaptureChannel,
                          pBasicCaptureChannelCfg->Event); 
}

/**
  * @brief  Configures an output basic one pulse mode 
  * @param  HRTIMx: pointer to HRTIMx peripheral
  * @param  TimerIdx: Timer index
  *                   This parameter can be one of the following values:
  *                   @arg 0x0 to 0x4 for timers A to E 
  * @param  OnePulseChannel: Timer output
  *                    This parameter can be one of the following values:
  *                    @arg HRTIM_OUTPUT_TA1: Timer A - Output 1
  *                    @arg HRTIM_OUTPUT_TA2: Timer A - Output 2
  *                    @arg HRTIM_OUTPUT_TB1: Timer B - Output 1
  *                    @arg HRTIM_OUTPUT_TB2: Timer B - Output 2
  *                    @arg HRTIM_OUTPUT_TC1: Timer C - Output 1
  *                    @arg HRTIM_OUTPUT_TC2: Timer C - Output 2
  *                    @arg HRTIM_OUTPUT_TD1: Timer D - Output 1
  *                    @arg HRTIM_OUTPUT_TD2: Timer D - Output 2
  *                    @arg HRTIM_OUTPUT_TE1: Timer E - Output 1
  *                    @arg HRTIM_OUTPUT_TE2: Timer E - Output 2 
  * @param  pBasicOnePulseChannelCfg: pointer to the basic one pulse output configuration structure
  * @note When the timer operates in basic one pulse mode:
  *         the timer counter is implicitly started by the reset event,
  *         the reset of the timer counter is triggered by the designated external event
  *         GPIO input is implicitly used as event source,
  *         Output 1 is implicitly controled by the compare unit 1,
  *         Output 2 is implicitly controled by the compare unit 2.
  *         Output Set/Reset crossbar is set as follows:
  *         Output 1: SETx1R = CMP1, RSTx1R = PER
  *         Output 2: SETx2R = CMP2, RST2R = PER
  *         The counter mode should be HRTIM_MODE_SINGLESHOT_RETRIGGERABLE
  * @retval None
  */
void HRTIM_SimpleOnePulseChannelConfig(HRTIM_TypeDef * HRTIM_,
                                                       uint32_t TimerIdx,
                                                       uint32_t OnePulseChannel,
                                                       HRTIM_BasicOnePulseChannelCfgTypeDef* pBasicOnePulseChannelCfg)
{
  uint32_t CompareUnit = HRTIM_COMPAREUNIT_1;
  HRTIM_CompareCfgTypeDef CompareCfg;
  HRTIM_OutputCfgTypeDef OutputCfg;
  HRTIM_EventCfgTypeDef EventCfg;
  
  /* Check parameters */
  assert_param(IS_HRTIM_TIMER_OUTPUT(TimerIdx, OnePulseChannel));
  assert_param(IS_HRTIM_OUTPUTPOLARITY(pBasicOnePulseChannelCfg->OutputPolarity));
  assert_param(IS_HRTIM_OUTPUTIDLESTATE(pBasicOnePulseChannelCfg->OutputIdleState));
  assert_param(IS_HRTIM_EVENT(pBasicOnePulseChannelCfg->Event));
  assert_param(IS_HRTIM_EVENTPOLARITY(pBasicOnePulseChannelCfg->EventPolarity));
  assert_param(IS_HRTIM_EVENTSENSITIVITY(pBasicOnePulseChannelCfg->EventSensitivity));
  assert_param(IS_HRTIM_EVENTFILTER(pBasicOnePulseChannelCfg->EventFilter));
  
  /* Configure timer compare unit */  
  switch (OnePulseChannel)
  {
    case HRTIM_OUTPUT_TA1:
    case HRTIM_OUTPUT_TB1:
    case HRTIM_OUTPUT_TC1:
    case HRTIM_OUTPUT_TD1:
    case HRTIM_OUTPUT_TE1:
    {
      CompareUnit = HRTIM_COMPAREUNIT_1;
    }
    break;
    case HRTIM_OUTPUT_TA2:
    case HRTIM_OUTPUT_TB2:
    case HRTIM_OUTPUT_TC2:
    case HRTIM_OUTPUT_TD2:
    case HRTIM_OUTPUT_TE2:
    {
      CompareUnit = HRTIM_COMPAREUNIT_2;
    }
    break;
    default:
    break;      
  }
  
  CompareCfg.CompareValue = pBasicOnePulseChannelCfg->Pulse;
  CompareCfg.AutoDelayedMode = HRTIM_AUTODELAYEDMODE_REGULAR;
  CompareCfg.AutoDelayedTimeout = 0;
  
  HRTIM_CompareUnitConfig(HRTIM_,
                          TimerIdx,
                          CompareUnit,
                          &CompareCfg);
  
  /* Configure timer output */
  OutputCfg.Polarity = pBasicOnePulseChannelCfg->OutputPolarity;
  OutputCfg.IdleState = pBasicOnePulseChannelCfg->OutputIdleState;
  OutputCfg.FaultState = HRTIM_OUTPUTFAULTSTATE_NONE;
  OutputCfg.IdleMode = HRTIM_OUTPUTIDLEMODE_NONE;
  OutputCfg.ChopperModeEnable = HRTIM_OUTPUTCHOPPERMODE_DISABLED;
  OutputCfg.BurstModeEntryDelayed = HRTIM_OUTPUTBURSTMODEENTRY_REGULAR;
  
  if (CompareUnit == HRTIM_COMPAREUNIT_1)
  {
    OutputCfg.SetSource = HRTIM_OUTPUTSET_TIMCMP1;
  }
  else
  {
    OutputCfg.SetSource = HRTIM_OUTPUTSET_TIMCMP2;
  }
  OutputCfg.ResetSource = HRTIM_OUTPUTSET_TIMPER;
  
  HRTIM_OutputConfig(HRTIM_,
                     TimerIdx,
                     OnePulseChannel,
                     &OutputCfg);  
  
  /* Configure external event channel */
  EventCfg.FastMode = HRTIM_EVENTFASTMODE_DISABLE;
  EventCfg.Filter = pBasicOnePulseChannelCfg->EventFilter;
  EventCfg.Polarity = pBasicOnePulseChannelCfg->EventPolarity;
  EventCfg.Sensitivity = pBasicOnePulseChannelCfg->EventSensitivity;
  EventCfg.Source = HRTIM_EVENTSRC_1;
    
  HRTIM_ExternalEventConfig(HRTIM_,
                    pBasicOnePulseChannelCfg->Event,
                    &EventCfg);

  /* Configure the timer reset register */
  HRTIM_TIM_ResetConfig(HRTIM_,
                        TimerIdx, 
                        pBasicOnePulseChannelCfg->Event);  
}

/**
  * @brief  Configures the general behavior of a timer operating in waveform mode 
  * @param  HRTIMx: pointer to HRTIMx peripheral
  * @param  TimerIdx: Timer index
  *                   This parameter can be one of the following values:
  *                   @arg 0x0 to 0x4 for timers A to E 
  * @param  pTimerCfg: pointer to the timer configuration structure
  * @note When the timer operates in waveform mode, all the features supported by
  *       the HRTIMx are available without any limitation.
  * @retval None
  */
void HRTIM_WaveformTimerConfig(HRTIM_TypeDef * HRTIMx,
                                                uint32_t TimerIdx,
                                                HRTIM_TimerCfgTypeDef * pTimerCfg)
{
  uint32_t HRTIM_timcr;
  uint32_t HRTIM_timfltr;
  uint32_t HRTIM_timoutr;
  uint32_t HRTIM_timrstr;

  /* Check parameters */
  assert_param(IS_HRTIM_TIMING_UNIT(TimerIdx));
  assert_param(IS_HRTIM_TIMPUSHPULLMODE(pTimerCfg->PushPull));
  assert_param(IS_HRTIM_TIMFAULTENABLE(pTimerCfg->FaultEnable));
  assert_param(IS_HRTIM_TIMFAULTLOCK(pTimerCfg->FaultLock));
  assert_param(IS_HRTIM_TIMDEADTIMEINSERTION(pTimerCfg->DeadTimeInsertion));
  assert_param(IS_HRTIM_TIMDELAYEDPROTECTION(pTimerCfg->DelayedProtectionMode));
  assert_param(IS_HRTIM_TIMUPDATETRIGGER(pTimerCfg->UpdateTrigger)); 
  assert_param(IS_HRTIM_TIMRESETTRIGGER(pTimerCfg->ResetTrigger));
  assert_param(IS_HRTIM_TIMUPDATEONRESET(pTimerCfg->ResetUpdate));

  /* Configure timing unit (Timer A to Timer E) */
  HRTIM_timcr = HRTIMx->HRTIM_TIMERx[TimerIdx].TIMxCR;
  HRTIM_timfltr  = HRTIMx->HRTIM_TIMERx[TimerIdx].FLTxR;
  HRTIM_timoutr  = HRTIMx->HRTIM_TIMERx[TimerIdx].OUTxR;
  HRTIM_timrstr  = HRTIMx->HRTIM_TIMERx[TimerIdx].RSTxR;
  
  /* Set the push-pull mode */
  HRTIM_timcr &= ~(HRTIM_TIMCR_PSHPLL);
  HRTIM_timcr |= pTimerCfg->PushPull;
  
  /* Enable/Disable registers update on timer counter reset */
  HRTIM_timcr &= ~(HRTIM_TIMCR_TRSTU);
  HRTIM_timcr |= pTimerCfg->ResetUpdate;
  
  /* Set the timer update trigger */
  HRTIM_timcr &= ~(HRTIM_TIMCR_TIMUPDATETRIGGER);
  HRTIM_timcr |= pTimerCfg->UpdateTrigger;
  
  /* Enable/Disable the fault channel at timer level */
  HRTIM_timfltr &= ~(HRTIM_FLTR_FLTxEN);
  HRTIM_timfltr |= (pTimerCfg->FaultEnable & HRTIM_FLTR_FLTxEN);
  
  /* Lock/Unlock fault sources at timer level */
  HRTIM_timfltr &= ~(HRTIM_FLTR_FLTCLK);
  HRTIM_timfltr |= pTimerCfg->FaultLock;
  
  /* Enable/Disable dead time insertion at timer level */
  HRTIM_timoutr &= ~(HRTIM_OUTR_DTEN);
  HRTIM_timoutr |= pTimerCfg->DeadTimeInsertion;

  /* Enable/Disable delayed protection at timer level */
  HRTIM_timoutr &= ~(HRTIM_OUTR_DLYPRT| HRTIM_OUTR_DLYPRTEN);
  HRTIM_timoutr |= pTimerCfg->DelayedProtectionMode;
  
  /* Set the timer counter reset trigger */
  HRTIM_timrstr = pTimerCfg->ResetTrigger;

  /* Update the HRTIMx registers */
  HRTIMx->HRTIM_TIMERx[TimerIdx].TIMxCR  = HRTIM_timcr;
  HRTIMx->HRTIM_TIMERx[TimerIdx].FLTxR = HRTIM_timfltr;
  HRTIMx->HRTIM_TIMERx[TimerIdx].OUTxR = HRTIM_timoutr;
  HRTIMx->HRTIM_TIMERx[TimerIdx].RSTxR = HRTIM_timrstr;
 }

/**
  * @brief  Configures the compare unit of a timer operating in waveform mode 
  * @param  HRTIMx: pointer to HRTIMx peripheral
  * @param  TimerIdx: Timer index
  *                   0xFF for master timer
  *                   This parameter can be one of the following values:
  *                   @arg 0x0 to 0x4 for timers A to E 
  * @param  CompareUnit: Compare unit to configure
  *                    This parameter can be one of the following values: 
  *                    @arg HRTIM_COMPAREUNIT_1: Compare unit 1
  *                    @arg HRTIM_COMPAREUNIT_2: Compare unit 2
  *                    @arg HRTIM_COMPAREUNIT_3: Compare unit 3
  *                    @arg HRTIM_COMPAREUNIT_4: Compare unit 4
  * @param  pCompareCfg: pointer to the compare unit configuration structure
  * @note When auto delayed mode is required for compare unit 2 or compare unit 4, 
  *       application has to configure separately the capture unit. Capture unit 
  *       to configure in that case depends on the compare unit auto delayed mode
  *       is applied to (see below):
  *         Auto delayed on output compare 2: capture unit 1 must be configured
  *         Auto delayed on output compare 4: capture unit 2 must be configured
  * @retval None
  */
 void HRTIM_WaveformCompareConfig(HRTIM_TypeDef * HRTIMx,
                                                  uint32_t TimerIdx,
                                                  uint32_t CompareUnit,
                                                  HRTIM_CompareCfgTypeDef* pCompareCfg)
{
    uint32_t HRTIM_timcr;

  /* Check parameters */
  assert_param(IS_HRTIM_TIMING_UNIT(TimerIdx));
  assert_param(IS_HRTIM_COMPAREUNIT_AUTODELAYEDMODE(CompareUnit, pCompareCfg->AutoDelayedMode));
  
  /* Configure the compare unit */
  switch (CompareUnit)
  {
    case HRTIM_COMPAREUNIT_1:
    {
      /* Set the compare value */
      HRTIMx->HRTIM_TIMERx[TimerIdx].CMP1xR = pCompareCfg->CompareValue;
    }
    break;
    case HRTIM_COMPAREUNIT_2:
    {
      /* Set the compare value */
      HRTIMx->HRTIM_TIMERx[TimerIdx].CMP2xR = pCompareCfg->CompareValue;
      
      if (pCompareCfg->AutoDelayedMode != HRTIM_AUTODELAYEDMODE_REGULAR)
      {
        /* Configure auto-delayed mode */
        HRTIM_timcr = HRTIMx->HRTIM_TIMERx[TimerIdx].TIMxCR;
        HRTIM_timcr &= ~HRTIM_TIMCR_DELCMP2;
        HRTIM_timcr |= pCompareCfg->AutoDelayedMode;
        HRTIMx->HRTIM_TIMERx[TimerIdx].TIMxCR = HRTIM_timcr;
        
        /* Set the compare value for timeout compare unit (if any) */
        if (pCompareCfg->AutoDelayedMode == HRTIM_AUTODELAYEDMODE_AUTODELAYED_TIMEOUTCMP1)
        {
          HRTIMx->HRTIM_TIMERx[TimerIdx].CMP1xR = pCompareCfg->AutoDelayedTimeout;
        }
        else if (pCompareCfg->AutoDelayedMode == HRTIM_AUTODELAYEDMODE_AUTODELAYED_TIMEOUTCMP3)
        {
          HRTIMx->HRTIM_TIMERx[TimerIdx].CMP3xR = pCompareCfg->AutoDelayedTimeout;
        }
      }
    }
    break;
    case HRTIM_COMPAREUNIT_3:
    {
      /* Set the compare value */
      HRTIMx->HRTIM_TIMERx[TimerIdx].CMP3xR = pCompareCfg->CompareValue;
    }
    break;
    case HRTIM_COMPAREUNIT_4:
    {
      /* Set the compare value */
      HRTIMx->HRTIM_TIMERx[TimerIdx].CMP4xR = pCompareCfg->CompareValue;
      
      if (pCompareCfg->AutoDelayedMode != HRTIM_AUTODELAYEDMODE_REGULAR)
      {
        /* Configure auto-delayed mode */
        HRTIM_timcr = HRTIMx->HRTIM_TIMERx[TimerIdx].TIMxCR;
        HRTIM_timcr &= ~HRTIM_TIMCR_DELCMP4;
        HRTIM_timcr |= (pCompareCfg->AutoDelayedMode << 2);
        HRTIMx->HRTIM_TIMERx[TimerIdx].TIMxCR = HRTIM_timcr;
        
        /* Set the compare value for timeout compare unit (if any) */
        if (pCompareCfg->AutoDelayedMode == HRTIM_AUTODELAYEDMODE_AUTODELAYED_TIMEOUTCMP1)
        {
          HRTIMx->HRTIM_TIMERx[TimerIdx].CMP1xR = pCompareCfg->AutoDelayedTimeout;
        }
        else if (pCompareCfg->AutoDelayedMode == HRTIM_AUTODELAYEDMODE_AUTODELAYED_TIMEOUTCMP3)
        {
          HRTIMx->HRTIM_TIMERx[TimerIdx].CMP3xR = pCompareCfg->AutoDelayedTimeout;
        }
      }
    }
    break;
    default:
    break;  
  }
}

/**
  * @brief  Sets the HRTIMx Master Comparex Register value 
  * @param  HRTIMx: pointer to HRTIMx peripheral
  * @param  CompareUnit: Compare unit to configure
  *                    This parameter can be one of the following values: 
  *                    @arg HRTIM_COMPAREUNIT_1: Compare unit 1
  *                    @arg HRTIM_COMPAREUNIT_2: Compare unit 2
  *                    @arg HRTIM_COMPAREUNIT_3: Compare unit 3
  *                    @arg HRTIM_COMPAREUNIT_4: Compare unit 4
  * @param  Compare: specifies the Comparex register new value
  * @retval None
  */
void HRTIM_MasterSetCompare(HRTIM_TypeDef * HRTIMx,
                                                  uint32_t CompareUnit,
                                                  uint32_t Compare)
{
  /* Check parameters */
  assert_param(IS_HRTIM_COMPAREUNIT(CompareUnit));
  
  /* Configure the compare unit */
  switch (CompareUnit)
  {
    case HRTIM_COMPAREUNIT_1:
    {
      /* Set the compare value */
      HRTIMx->HRTIM_MASTER.MCMP1R = Compare;
    }
    break;
    case HRTIM_COMPAREUNIT_2:
    {
      /* Set the compare value */
      HRTIMx->HRTIM_MASTER.MCMP2R = Compare;
    }
    break;
    case HRTIM_COMPAREUNIT_3:
    {
      /* Set the compare value */
      HRTIMx->HRTIM_MASTER.MCMP3R = Compare;
    }
    break;
    case HRTIM_COMPAREUNIT_4:
    {
      /* Set the compare value */
      HRTIMx->HRTIM_MASTER.MCMP4R = Compare;
    }
    break;
    default:
    break;
  }  
}
/**
  * @brief  Configures the capture unit of a timer operating in waveform mode 
  * @param  HRTIMx: pointer to HRTIMx peripheral
  * @param  TimerIdx: Timer index
  *                   This parameter can be one of the following values:
  *                   @arg 0x0 to 0x4 for timers A to E 
  * @param  CaptureChannel: Capture unit to configure
  *                    This parameter can be one of the following values: 
  *                    @arg HRTIM_CAPTUREUNIT_1: Capture unit 1
  *                    @arg HRTIM_CAPTUREUNIT_2: Capture unit 2
  * @param  pCaptureCfg: pointer to the compare unit configuration structure
  * @retval None
  */
void HRTIM_WaveformCaptureConfig(HRTIM_TypeDef * HRTIMx,
                                                  uint32_t TimerIdx,
                                                  uint32_t CaptureUnit,
                                                  HRTIM_CaptureCfgTypeDef* pCaptureCfg)
{
  /* Configure the capture unit */
  switch (CaptureUnit)
  {
    case HRTIM_CAPTUREUNIT_1:
    {
      HRTIMx->HRTIM_TIMERx[TimerIdx].CPT1xCR = pCaptureCfg->Trigger;
    }
    break;
    case HRTIM_CAPTUREUNIT_2:
    {
      HRTIMx->HRTIM_TIMERx[TimerIdx].CPT2xCR = pCaptureCfg->Trigger;
    }
    break;
    default:
    break;
  }
}

/**
  * @brief  Configures the output of a timer operating in waveform mode 
  * @param  HRTIMx: pointer to HRTIMx peripheral
  * @param  TimerIdx: Timer index
  *                   This parameter can be one of the following values:
  *                   @arg 0x0 to 0x4 for timers A to E 
  * @param  Output: Timer output
  *                    This parameter can be one of the following values:
  *                    @arg HRTIM_OUTPUT_TA1: Timer A - Output 1
  *                    @arg HRTIM_OUTPUT_TA2: Timer A - Output 2
  *                    @arg HRTIM_OUTPUT_TB1: Timer B - Output 1
  *                    @arg HRTIM_OUTPUT_TB2: Timer B - Output 2
  *                    @arg HRTIM_OUTPUT_TC1: Timer C - Output 1
  *                    @arg HRTIM_OUTPUT_TC2: Timer C - Output 2
  *                    @arg HRTIM_OUTPUT_TD1: Timer D - Output 1
  *                    @arg HRTIM_OUTPUT_TD2: Timer D - Output 2
  *                    @arg HRTIM_OUTPUT_TE1: Timer E - Output 1
  *                    @arg HRTIM_OUTPUT_TE2: Timer E - Output 2 
  * @param  pOutputCfg: pointer to the timer output configuration structure
  * @retval None
  */
void HRTIM_WaveformOutputConfig(HRTIM_TypeDef * HRTIM_,
                                                uint32_t TimerIdx,
                                                uint32_t Output,
                                                HRTIM_OutputCfgTypeDef * pOutputCfg)
{
  /* Check parameters */
  assert_param(IS_HRTIM_TIMER_OUTPUT(TimerIdx, Output));
  assert_param(IS_HRTIM_OUTPUTPOLARITY(pOutputCfg->Polarity));
  assert_param(IS_HRTIM_OUTPUTIDLESTATE(pOutputCfg->IdleState));
  assert_param(IS_HRTIM_OUTPUTIDLEMODE(pOutputCfg->IdleMode));
  assert_param(IS_HRTIM_OUTPUTFAULTSTATE(pOutputCfg->FaultState));
  assert_param(IS_HRTIM_OUTPUTCHOPPERMODE(pOutputCfg->ChopperModeEnable));
  assert_param(IS_HRTIM_OUTPUTBURSTMODEENTRY(pOutputCfg->BurstModeEntryDelayed));

  /* Configure the timer output */
  HRTIM_OutputConfig(HRTIM_, TimerIdx, Output, pOutputCfg);  
}

/**
  * @brief  Configures the event filtering capabilities of a timer (blanking, windowing) 
  * @param  HRTIMx: pointer to HRTIMx peripheral
  * @param  TimerIdx: Timer index
  *                   This parameter can be one of the following values:
  *                   @arg 0x0 to 0x4 for timers A to E 
  * @param  Event: external event for which timer event filtering must be configured
  *                    This parameter can be one of the following values:
  *                    @arg HRTIM_EVENT_1: External event 1
  *                    @arg HRTIM_EVENT_2: External event 2
  *                    @arg HRTIM_EVENT_3: External event 3
  *                    @arg HRTIM_EVENT_4: External event 4
  *                    @arg HRTIM_EVENT_5: External event 5
  *                    @arg HRTIM_EVENT_6: External event 6
  *                    @arg HRTIM_EVENT_7: External event 7
  *                    @arg HRTIM_EVENT_8: External event 8
  *                    @arg HRTIM_EVENT_9: External event 9
  *                    @arg HRTIM_EVENT_10: External event 10
  * @param  pTimerEventFilteringCfg: pointer to the timer event filtering configuration structure
  * @retval None
  */
void HRTIM_TimerEventFilteringConfig(HRTIM_TypeDef * HRTIMx,
                                                      uint32_t TimerIdx,
                                                      uint32_t Event,
                                                      HRTIM_TimerEventFilteringCfgTypeDef* pTimerEventFilteringCfg)
{
  uint32_t HRTIM_eefr;
  
  /* Check parameters */
  assert_param(IS_HRTIM_TIMING_UNIT(TimerIdx));
  assert_param(IS_HRTIM_EVENT(Event));
  assert_param(IS_HRTIM_TIMEVENTFILTER(pTimerEventFilteringCfg->Filter));
  assert_param(IS_HRTIM_TIMEVENTLATCH(pTimerEventFilteringCfg->Latch));

  /* Configure timer event filtering capabilities */
  switch (Event)
  {
    case HRTIM_TIMEVENTFILTER_NONE:
    {
      HRTIMx->HRTIM_TIMERx[TimerIdx].EEFxR1 = 0;
      HRTIMx->HRTIM_TIMERx[TimerIdx].EEFxR2 = 0;
    }
    break;
    case HRTIM_EVENT_1:
    {
      HRTIM_eefr = HRTIMx->HRTIM_TIMERx[TimerIdx].EEFxR1;
      HRTIM_eefr &= ~(HRTIM_EEFR1_EE1FLTR | HRTIM_EEFR1_EE1LTCH);
      HRTIM_eefr |= (pTimerEventFilteringCfg->Filter | pTimerEventFilteringCfg->Latch);
      HRTIMx->HRTIM_TIMERx[TimerIdx].EEFxR1 = HRTIM_eefr;
    }
    break;
    case HRTIM_EVENT_2:
    {
      HRTIM_eefr = HRTIMx->HRTIM_TIMERx[TimerIdx].EEFxR1;
      HRTIM_eefr &= ~(HRTIM_EEFR1_EE2FLTR | HRTIM_EEFR1_EE2LTCH);
      HRTIM_eefr |= ((pTimerEventFilteringCfg->Filter | pTimerEventFilteringCfg->Latch) << 6);
      HRTIMx->HRTIM_TIMERx[TimerIdx].EEFxR1 = HRTIM_eefr;
    }
    break;
    case HRTIM_EVENT_3:
    {
      HRTIM_eefr = HRTIMx->HRTIM_TIMERx[TimerIdx].EEFxR1;
      HRTIM_eefr &= ~(HRTIM_EEFR1_EE3FLTR | HRTIM_EEFR1_EE3LTCH);
      HRTIM_eefr |= ((pTimerEventFilteringCfg->Filter | pTimerEventFilteringCfg->Latch) << 12);
      HRTIMx->HRTIM_TIMERx[TimerIdx].EEFxR1 = HRTIM_eefr;
    }
    break;
    case HRTIM_EVENT_4:
    {
      HRTIM_eefr = HRTIMx->HRTIM_TIMERx[TimerIdx].EEFxR1;
      HRTIM_eefr &= ~(HRTIM_EEFR1_EE4FLTR | HRTIM_EEFR1_EE4LTCH);
      HRTIM_eefr |= ((pTimerEventFilteringCfg->Filter | pTimerEventFilteringCfg->Latch) << 18);
      HRTIMx->HRTIM_TIMERx[TimerIdx].EEFxR1 = HRTIM_eefr;
    }
    break;
    case HRTIM_EVENT_5:
    {
      HRTIM_eefr = HRTIMx->HRTIM_TIMERx[TimerIdx].EEFxR1;
      HRTIM_eefr &= ~(HRTIM_EEFR1_EE5FLTR | HRTIM_EEFR1_EE5LTCH);
      HRTIM_eefr |= ((pTimerEventFilteringCfg->Filter | pTimerEventFilteringCfg->Latch) << 24);
      HRTIMx->HRTIM_TIMERx[TimerIdx].EEFxR1 = HRTIM_eefr;
    }
    break;
    case HRTIM_EVENT_6:
    {
      HRTIM_eefr = HRTIMx->HRTIM_TIMERx[TimerIdx].EEFxR2;
      HRTIM_eefr &= ~(HRTIM_EEFR2_EE6FLTR | HRTIM_EEFR2_EE6LTCH);
      HRTIM_eefr |= (pTimerEventFilteringCfg->Filter | pTimerEventFilteringCfg->Latch);
      HRTIMx->HRTIM_TIMERx[TimerIdx].EEFxR2 = HRTIM_eefr;
    }
    break;
    case HRTIM_EVENT_7:
    {
      HRTIM_eefr = HRTIMx->HRTIM_TIMERx[TimerIdx].EEFxR2;
      HRTIM_eefr &= ~(HRTIM_EEFR2_EE7FLTR | HRTIM_EEFR2_EE7LTCH);
      HRTIM_eefr |= ((pTimerEventFilteringCfg->Filter | pTimerEventFilteringCfg->Latch) << 6);
      HRTIMx->HRTIM_TIMERx[TimerIdx].EEFxR2 = HRTIM_eefr;
    }
    break;
    case HRTIM_EVENT_8:
    {
      HRTIM_eefr = HRTIMx->HRTIM_TIMERx[TimerIdx].EEFxR2;
      HRTIM_eefr &= ~(HRTIM_EEFR2_EE8FLTR | HRTIM_EEFR2_EE8LTCH);
      HRTIM_eefr |= ((pTimerEventFilteringCfg->Filter | pTimerEventFilteringCfg->Latch) << 12);
      HRTIMx->HRTIM_TIMERx[TimerIdx].EEFxR2 = HRTIM_eefr;
    }
    break;
    case HRTIM_EVENT_9:
    {
      HRTIM_eefr = HRTIMx->HRTIM_TIMERx[TimerIdx].EEFxR2;
      HRTIM_eefr &= ~(HRTIM_EEFR2_EE9FLTR | HRTIM_EEFR2_EE9LTCH);
      HRTIM_eefr |= ((pTimerEventFilteringCfg->Filter | pTimerEventFilteringCfg->Latch) << 18);
      HRTIMx->HRTIM_TIMERx[TimerIdx].EEFxR2 = HRTIM_eefr;
    }
    break;
    case HRTIM_EVENT_10:
    {
      HRTIM_eefr = HRTIMx->HRTIM_TIMERx[TimerIdx].EEFxR2;
      HRTIM_eefr &= ~(HRTIM_EEFR2_EE10FLTR | HRTIM_EEFR2_EE10LTCH);
      HRTIM_eefr |= ((pTimerEventFilteringCfg->Filter | pTimerEventFilteringCfg->Latch) << 24);
      HRTIMx->HRTIM_TIMERx[TimerIdx].EEFxR2 = HRTIM_eefr;
    }
    break;
    default:
    break;
  }
}

/**
  * @brief  Configures the dead time insertion feature for a timer 
  * @param  HRTIMx: pointer to HRTIMx peripheral
  * @param  TimerIdx: Timer index
  *                   This parameter can be one of the following values:
  *                   @arg 0x0 to 0x4 for timers A to E 
  * @param  pDeadTimeCfg: pointer to the dead time insertion configuration structure
  * @retval None
  */
void HRTIM_DeadTimeConfig(HRTIM_TypeDef * HRTIMx,
                                           uint32_t TimerIdx,
                                           HRTIM_DeadTimeCfgTypeDef* pDeadTimeCfg)
{
  uint32_t HRTIM_dtr;
  
  /* Check parameters */
  assert_param(IS_HRTIM_TIMING_UNIT(TimerIdx));
  assert_param(IS_HRTIM_TIMDEADTIME_RISINGSIGN(pDeadTimeCfg->RisingSign));
  assert_param(IS_HRTIM_TIMDEADTIME_RISINGLOCK(pDeadTimeCfg->RisingLock));
  assert_param(IS_HRTIM_TIMDEADTIME_RISINGSIGNLOCK(pDeadTimeCfg->RisingSignLock));
  assert_param(IS_HRTIM_TIMDEADTIME_FALLINGSIGN(pDeadTimeCfg->FallingSign));
  assert_param(IS_HRTIM_TIMDEADTIME_FALLINGLOCK(pDeadTimeCfg->FallingLock));
  assert_param(IS_HRTIM_TIMDEADTIME_FALLINGSIGNLOCK(pDeadTimeCfg->FallingSignLock));

  HRTIM_dtr = HRTIMx->HRTIM_TIMERx[TimerIdx].DTxR;
     
  /* Clear timer dead times configuration */
  HRTIM_dtr &= ~(HRTIM_DTR_DTR | HRTIM_DTR_SDTR | HRTIM_DTR_DTPRSC |
                 HRTIM_DTR_DTRSLK | HRTIM_DTR_DTRLK | HRTIM_DTR_SDTF |
                 HRTIM_DTR_SDTR | HRTIM_DTR_DTFSLK | HRTIM_DTR_DTFLK);
  
  /* Set timer dead times configuration */
  HRTIM_dtr |= (pDeadTimeCfg->Prescaler << 10);
  HRTIM_dtr |= pDeadTimeCfg->RisingValue;
  HRTIM_dtr |= pDeadTimeCfg->RisingSign;
  HRTIM_dtr |= pDeadTimeCfg->RisingSignLock;
  HRTIM_dtr |= pDeadTimeCfg->RisingLock;
  HRTIM_dtr |= (pDeadTimeCfg->FallingValue << 16);
  HRTIM_dtr |= pDeadTimeCfg->FallingSign;
  HRTIM_dtr |= pDeadTimeCfg->FallingSignLock;
  HRTIM_dtr |= pDeadTimeCfg->FallingLock;
    
  /* Update the HRTIMx registers */  
  HRTIMx->HRTIM_TIMERx[TimerIdx].DTxR = HRTIM_dtr;
}

/**
  * @brief  Configures the chopper mode feature for a timer 
  * @param  HRTIMx: pointer to HRTIMx peripheral
  * @param  TimerIdx: Timer index
  *                   This parameter can be one of the following values:
  *                   @arg 0x0 to 0x4 for timers A to E 
  * @param  pChopperModeCfg: pointer to the chopper mode configuration structure
  * @retval None
  */
void HRTIM_ChopperModeConfig(HRTIM_TypeDef * HRTIMx,
                                              uint32_t TimerIdx,
                                              HRTIM_ChopperModeCfgTypeDef* pChopperModeCfg)
{
  uint32_t HRTIM_chpr;
  
  /* Check parameters */
  assert_param(IS_HRTIM_TIMING_UNIT(TimerIdx));

  HRTIM_chpr = HRTIMx->HRTIM_TIMERx[TimerIdx].CHPxR;
     
  /* Clear timer chopper mode configuration */
  HRTIM_chpr &= ~(HRTIM_CHPR_CARFRQ | HRTIM_CHPR_CARDTY | HRTIM_CHPR_STRPW);
  
  /* Set timer chopper mode configuration */
  HRTIM_chpr |= pChopperModeCfg->CarrierFreq;
  HRTIM_chpr |= (pChopperModeCfg->DutyCycle << 4);
  HRTIM_chpr |= (pChopperModeCfg->StartPulse << 7);
    
  /* Update the HRTIMx registers */  
  HRTIMx->HRTIM_TIMERx[TimerIdx].CHPxR = HRTIM_chpr;
}

/**
  * @brief  Configures the burst DMA controller for a timer 
  * @param  HRTIMx: pointer to HRTIMx peripheral
  * @param  TimerIdx: Timer index
   *                  This parameter can be one of the following values:
 *                    @arg 0x5 for master timer
  *                   @arg 0x0 to 0x4 for timers A to E 
  * @param  RegistersToUpdate: registers to be written by DMA
  *                    This parameter can be any combination of the following values:
  *                    @arg HRTIM_BURSTDMA_CR: HRTIM_MCR or HRTIM_TIMxCR
  *                    @arg HRTIM_BURSTDMA_ICR: HRTIM_MICR or HRTIM_TIMxICR
  *                    @arg HRTIM_BURSTDMA_DIER: HRTIM_MDIER or HRTIM_TIMxDIER
  *                    @arg HRTIM_BURSTDMA_CNT: HRTIM_MCNT or HRTIM_TIMxCNT
  *                    @arg HRTIM_BURSTDMA_PER: HRTIM_MPER or HRTIM_TIMxPER
  *                    @arg HRTIM_BURSTDMA_REP: HRTIM_MREP or HRTIM_TIMxREP
  *                    @arg HRTIM_BURSTDMA_CMP1: HRTIM_MCMP1 or HRTIM_TIMxCMP1
  *                    @arg HRTIM_BURSTDMA_CMP2: HRTIM_MCMP2 or HRTIM_TIMxCMP2
  *                    @arg HRTIM_BURSTDMA_CMP3: HRTIM_MCMP3 or HRTIM_TIMxCMP3
  *                    @arg HRTIM_BURSTDMA_CMP4: HRTIM_MCMP4 or HRTIM_TIMxCMP4
  *                    @arg HRTIM_BURSTDMA_DTR: HRTIM_TIMxDTR
  *                    @arg HRTIM_BURSTDMA_SET1R: HRTIM_TIMxSET1R
  *                    @arg HRTIM_BURSTDMA_RST1R: HRTIM_TIMxRST1R
  *                    @arg HRTIM_BURSTDMA_SET2R: HRTIM_TIMxSET2R
  *                    @arg HRTIM_BURSTDMA_RST2R: HRTIM_TIMxRST2R
  *                    @arg HRTIM_BURSTDMA_EEFR1: HRTIM_TIMxEEFR1
  *                    @arg HRTIM_BURSTDMA_EEFR2: HRTIM_TIMxEEFR2
  *                    @arg HRTIM_BURSTDMA_RSTR: HRTIM_TIMxRSTR
  *                    @arg HRTIM_BURSTDMA_CHPR: HRTIM_TIMxCHPR
  *                    @arg HRTIM_BURSTDMA_OUTR: HRTIM_TIMxOUTR
  *                    @arg HRTIM_BURSTDMA_FLTR: HRTIM_TIMxFLTR
  * @retval None
  */
void HRTIM_BurstDMAConfig(HRTIM_TypeDef * HRTIMx,
                                           uint32_t TimerIdx,
                                           uint32_t RegistersToUpdate)
{
  /* Check parameters */
  assert_param(IS_HRTIM_TIMER_BURSTDMA(TimerIdx, RegistersToUpdate));
  
  /* Set the burst DMA timer update register */
  switch (TimerIdx) 
  {
    case HRTIM_TIMERINDEX_TIMER_A:
    {
      HRTIMx->HRTIM_COMMON.BDTAUPR = RegistersToUpdate;
    }
    break;
    case HRTIM_TIMERINDEX_TIMER_B:
    {
      HRTIMx->HRTIM_COMMON.BDTBUPR = RegistersToUpdate;
    }
    break;
    case HRTIM_TIMERINDEX_TIMER_C:
    {
      HRTIMx->HRTIM_COMMON.BDTCUPR = RegistersToUpdate;
    }
    break;
    case HRTIM_TIMERINDEX_TIMER_D:
    {
      HRTIMx->HRTIM_COMMON.BDTDUPR = RegistersToUpdate;
    }
    break;
    case HRTIM_TIMERINDEX_TIMER_E:
    {
      HRTIMx->HRTIM_COMMON.BDTEUPR = RegistersToUpdate;
    }
    break;
    case HRTIM_TIMERINDEX_MASTER:
    {
      HRTIMx->HRTIM_COMMON.BDMUPDR = RegistersToUpdate;
    }
    break;
    default:
    break;
  }
}

/**
  * @brief  Configures the external input/output synchronization of the HRTIMx 
  * @param  HRTIMx: pointer to HRTIMx peripheral
  * @param  pSynchroCfg: pointer to the input/output synchronization configuration structure
  * @retval None
  */
void HRTIM_SynchronizationConfig(HRTIM_TypeDef *HRTIMx, HRTIM_SynchroCfgTypeDef * pSynchroCfg)
{
  uint32_t HRTIM_mcr;
  
  /* Check parameters */
  assert_param(IS_HRTIM_SYNCINPUTSOURCE(pSynchroCfg->SyncInputSource));
  assert_param(IS_HRTIM_SYNCOUTPUTSOURCE(pSynchroCfg->SyncOutputSource));
  assert_param(IS_HRTIM_SYNCOUTPUTPOLARITY(pSynchroCfg->SyncOutputPolarity));
    
  HRTIM_mcr = HRTIMx->HRTIM_MASTER.MCR;

  /* Set the synchronization input source */
  HRTIM_mcr &= ~(HRTIM_MCR_SYNC_IN);
  HRTIM_mcr |= pSynchroCfg->SyncInputSource;
  
  /* Set the event to be sent on the synchronization output */
  HRTIM_mcr &= ~(HRTIM_MCR_SYNC_SRC);
  HRTIM_mcr |= pSynchroCfg->SyncOutputSource;
  
  /* Set the polarity of the synchronization output */
  HRTIM_mcr &= ~(HRTIM_MCR_SYNC_OUT);
  HRTIM_mcr |= pSynchroCfg->SyncOutputPolarity;
  
  /* Update the HRTIMx registers */  
  HRTIMx->HRTIM_MASTER.MCR = HRTIM_mcr;
}

/**
  * @brief  Configures the burst mode feature of the HRTIMx 
  * @param  HRTIMx: pointer to HRTIMx peripheral
  * @param  pBurstModeCfg: pointer to the burst mode configuration structure
  * @retval None
  */
void HRTIM_BurstModeConfig(HRTIM_TypeDef * HRTIMx,
                                            HRTIM_BurstModeCfgTypeDef* pBurstModeCfg)
{
  uint32_t HRTIM_bmcr;

  /* Check parameters */
  assert_param(IS_HRTIM_BURSTMODE(pBurstModeCfg->Mode));
  assert_param(IS_HRTIM_BURSTMODECLOCKSOURCE(pBurstModeCfg->ClockSource));
  assert_param(IS_HRTIM_HRTIM_BURSTMODEPRESCALER(pBurstModeCfg->Prescaler));
  assert_param(IS_HRTIM_BURSTMODEPRELOAD(pBurstModeCfg->PreloadEnable));
  
  HRTIM_bmcr = HRTIMx->HRTIM_COMMON.BMCR;

  /* Set the burst mode operating mode */
  HRTIM_bmcr &= ~(HRTIM_BMCR_BMOM);
  HRTIM_bmcr |= pBurstModeCfg->Mode;
  
  /* Set the burst mode clock source */
  HRTIM_bmcr &= ~(HRTIM_BMCR_BMCLK);
  HRTIM_bmcr |= pBurstModeCfg->ClockSource;
  
  /* Set the burst mode prescaler */
  HRTIM_bmcr &= ~(HRTIM_BMCR_BMPSC);
  HRTIM_bmcr |= pBurstModeCfg->Prescaler;
 
  /* Enable/disable burst mode registers preload */
  HRTIM_bmcr &= ~(HRTIM_BMCR_BMPREN);
  HRTIM_bmcr |= pBurstModeCfg->PreloadEnable;
 
  /* Set the burst mode trigger */
  HRTIMx->HRTIM_COMMON.BMTRGR = pBurstModeCfg->Trigger;
  
  /* Set the burst mode compare value */
  HRTIMx->HRTIM_COMMON.BMCMPR = pBurstModeCfg->IdleDuration;
  
  /* Set the burst mode period */
  HRTIMx->HRTIM_COMMON.BMPER = pBurstModeCfg->Period;
  
  /* Update the HRTIMx registers */  
  HRTIMx->HRTIM_COMMON.BMCR = HRTIM_bmcr;
}

/**
  * @brief  Configures the conditioning of an external event
  * @param  HRTIMx: pointer to HRTIMx peripheral
  * @param  Event: external event to configure
  *                    This parameter can be one of the following values:
  *                    @arg HRTIM_EVENT_1: External event 1
  *                    @arg HRTIM_EVENT_2: External event 2
  *                    @arg HRTIM_EVENT_3: External event 3
  *                    @arg HRTIM_EVENT_4: External event 4
  *                    @arg HRTIM_EVENT_5: External event 5
  *                    @arg HRTIM_EVENT_6: External event 6
  *                    @arg HRTIM_EVENT_7: External event 7
  *                    @arg HRTIM_EVENT_8: External event 8
  *                    @arg HRTIM_EVENT_9: External event 9
  *                    @arg HRTIM_EVENT_10: External event 10
  * @param  pEventCfg: pointer to the event conditioning configuration structure
  * @retval None
  */
void HRTIM_EventConfig(HRTIM_TypeDef * HRTIMx,
                                        uint32_t Event,
                                        HRTIM_EventCfgTypeDef* pEventCfg)
{
  /* Check parameters */
  assert_param(IS_HRTIM_EVENTSRC(pEventCfg->Source)); 
  assert_param(IS_HRTIM_EVENTPOLARITY(pEventCfg->Polarity)); 
  assert_param(IS_HRTIM_EVENTSENSITIVITY(pEventCfg->Sensitivity)); 
  assert_param(IS_HRTIM_EVENTFASTMODE(pEventCfg->FastMode)); 
  assert_param(IS_HRTIM_EVENTFILTER(pEventCfg->Filter)); 

  /* Configure the event channel */
  HRTIM_ExternalEventConfig(HRTIMx, Event, pEventCfg);
 
}

/**
  * @brief  Configures the external event conditioning block prescaler
  * @param  HRTIMx: pointer to HRTIMx peripheral
  * @param  Prescaler: Prescaler value
  *                    This parameter can be one of the following values:
  *                    @arg HRTIM_EVENTPRESCALER_DIV1: fEEVS=fHRTIMx
  *                    @arg HRTIM_EVENTPRESCALER_DIV2: fEEVS=fHRTIMx / 2
  *                    @arg HRTIM_EVENTPRESCALER_DIV4: fEEVS=fHRTIMx / 4
  *                    @arg HRTIM_EVENTPRESCALER_DIV8: fEEVS=fHRTIMx / 8
  * @retval None
  */
void HRTIM_EventPrescalerConfig(HRTIM_TypeDef * HRTIMx,
                                                 uint32_t Prescaler)
{
  uint32_t HRTIM_eecr3;

  /* Check parameters */
  assert_param(IS_HRTIM_EVENTPRESCALER(Prescaler));

  /* Set the external event prescaler */
  HRTIM_eecr3 = HRTIMx->HRTIM_COMMON.EECR3;
  HRTIM_eecr3 &= ~(HRTIM_EECR3_EEVSD);
  HRTIM_eecr3 |= Prescaler;
  
  /* Update the HRTIMx registers */
  HRTIMx->HRTIM_COMMON.EECR3 = HRTIM_eecr3;
}
 
/**
  * @brief  Configures the conditioning of fault input
  * @param  HRTIMx: pointer to HRTIMx peripheral
  * @param  Fault: fault input to configure
  *                    This parameter can be one of the following values:
  *                    @arg HRTIM_FAULT_1: Fault input 1
  *                    @arg HRTIM_FAULT_2: Fault input 2
  *                    @arg HRTIM_FAULT_3: Fault input 3
  *                    @arg HRTIM_FAULT_4: Fault input 4
  *                    @arg HRTIM_FAULT_5: Fault input 5
  * @param  pFaultCfg: pointer to the fault conditioning configuration structure
  * @retval None
  */
void HRTIM_FaultConfig(HRTIM_TypeDef * HRTIMx,
                                        HRTIM_FaultCfgTypeDef* pFaultCfg,
                                        uint32_t Fault)
{
  uint32_t HRTIM_fltinr1;
  uint32_t HRTIM_fltinr2;

  /* Check parameters */
  assert_param(IS_HRTIM_FAULT(Fault));
  assert_param(IS_HRTIM_FAULTSOURCE(pFaultCfg->Source));
  assert_param(IS_HRTIM_FAULTPOLARITY(pFaultCfg->Polarity));
  assert_param(IS_HRTIM_FAULTFILTER(pFaultCfg->Filter));
  assert_param(IS_HRTIM_FAULTLOCK(pFaultCfg->Lock));

  /* Configure fault channel */
  HRTIM_fltinr1 = HRTIMx->HRTIM_COMMON.FLTINxR1;
  HRTIM_fltinr2 = HRTIMx->HRTIM_COMMON.FLTINxR2;
  
  switch (Fault)
  {
    case HRTIM_FAULT_1:
    {
      HRTIM_fltinr1 &= ~(HRTIM_FLTINR1_FLT1P | HRTIM_FLTINR1_FLT1SRC | HRTIM_FLTINR1_FLT1F | HRTIM_FLTINR1_FLT1LCK);
      HRTIM_fltinr1 |= pFaultCfg->Polarity;
      HRTIM_fltinr1 |= pFaultCfg->Source;
      HRTIM_fltinr1 |= pFaultCfg->Filter;
      HRTIM_fltinr1 |= pFaultCfg->Lock;
    }
    break;
    case HRTIM_FAULT_2:
    {
      HRTIM_fltinr1 &= ~(HRTIM_FLTINR1_FLT2P | HRTIM_FLTINR1_FLT2SRC | HRTIM_FLTINR1_FLT2F | HRTIM_FLTINR1_FLT2LCK);
      HRTIM_fltinr1 |= (pFaultCfg->Polarity << 8);
      HRTIM_fltinr1 |= (pFaultCfg->Source << 8);
      HRTIM_fltinr1 |= (pFaultCfg->Filter << 8);
      HRTIM_fltinr1 |= (pFaultCfg->Lock << 8);
    }
    break;
    case HRTIM_FAULT_3:
    {
      HRTIM_fltinr1 &= ~(HRTIM_FLTINR1_FLT3P | HRTIM_FLTINR1_FLT3SRC | HRTIM_FLTINR1_FLT3F | HRTIM_FLTINR1_FLT3LCK);
      HRTIM_fltinr1 |= (pFaultCfg->Polarity << 16);
      HRTIM_fltinr1 |= (pFaultCfg->Source << 16);
      HRTIM_fltinr1 |= (pFaultCfg->Filter << 16);
      HRTIM_fltinr1 |= (pFaultCfg->Lock << 16);
    }
    break;
    case HRTIM_FAULT_4:
    {
      HRTIM_fltinr1 &= ~(HRTIM_FLTINR1_FLT4P | HRTIM_FLTINR1_FLT4SRC | HRTIM_FLTINR1_FLT4F | HRTIM_FLTINR1_FLT4LCK);
      HRTIM_fltinr1 |= (pFaultCfg->Polarity << 24);
      HRTIM_fltinr1 |= (pFaultCfg->Source << 24);
      HRTIM_fltinr1 |= (pFaultCfg->Filter << 24);
      HRTIM_fltinr1 |= (pFaultCfg->Lock << 24);
    }
    break;
    case HRTIM_FAULT_5:
    {
      HRTIM_fltinr2 &= ~(HRTIM_FLTINR2_FLT5P | HRTIM_FLTINR2_FLT5SRC | HRTIM_FLTINR2_FLT5F | HRTIM_FLTINR2_FLT5LCK);
      HRTIM_fltinr2 |= pFaultCfg->Polarity;
      HRTIM_fltinr2 |= pFaultCfg->Source;
      HRTIM_fltinr2 |= pFaultCfg->Filter;
      HRTIM_fltinr2 |= pFaultCfg->Lock;
    }
    break;
    default:
    break;
  }

  /* Update the HRTIMx registers */
  HRTIMx->HRTIM_COMMON.FLTINxR1 = HRTIM_fltinr1;
  HRTIMx->HRTIM_COMMON.FLTINxR2 = HRTIM_fltinr2;
}

/**
  * @brief  Configures the fault conditioning block prescaler
  * @param  HRTIMx: pointer to HRTIMx peripheral
  * @param  Prescaler: Prescaler value
  *                    This parameter can be one of the following values:
  *                    @arg HRTIM_FAULTPRESCALER_DIV1: fFLTS=fHRTIMx
  *                    @arg HRTIM_FAULTPRESCALER_DIV2: fFLTS=fHRTIMx / 2
  *                    @arg HRTIM_FAULTPRESCALER_DIV4: fFLTS=fHRTIMx / 4
  *                    @arg HRTIM_FAULTPRESCALER_DIV8: fFLTS=fHRTIMx / 8
  * @retval None
  */
void HRTIM_FaultPrescalerConfig(HRTIM_TypeDef * HRTIMx,
                                                 uint32_t Prescaler)
{
  uint32_t HRTIM_fltinr2;

  /* Check parameters */
  assert_param(IS_HRTIM_FAULTPRESCALER(Prescaler));
  
  /* Set the external event prescaler */
  HRTIM_fltinr2 = HRTIMx->HRTIM_COMMON.FLTINxR2;
  HRTIM_fltinr2 &= ~(HRTIM_FLTINR2_FLTSD);
  HRTIM_fltinr2 |= Prescaler;
  
  /* Update the HRTIMx registers */
  HRTIMx->HRTIM_COMMON.FLTINxR2 = HRTIM_fltinr2;
}

/**
  * @brief  Enables or disables the HRTIMx Fault mode.
  * @param  HRTIMx: pointer to HRTIMx peripheral
  * @param  Fault: fault input to configure
  *                    This parameter can be one of the following values:
  *                    @arg HRTIM_FAULT_1: Fault input 1
  *                    @arg HRTIM_FAULT_2: Fault input 2
  *                    @arg HRTIM_FAULT_3: Fault input 3
  *                    @arg HRTIM_FAULT_4: Fault input 4
  *                    @arg HRTIM_FAULT_5: Fault input 5
  * @param  Enable: Fault mode controller enabling
  *                    This parameter can be one of the following values:
  *                    @arg HRTIM_FAULT_ENABLED: Fault mode enabled
  *                    @arg HRTIM_FAULT_DISABLED: Fault mode disabled
  * @retval None
  */
void HRTIM_FaultModeCtl(HRTIM_TypeDef * HRTIMx, uint32_t Fault, uint32_t Enable)
{
  uint32_t HRTIM_fltinr1;
  uint32_t HRTIM_fltinr2;
  
  /* Check parameters */
  assert_param(IS_HRTIM_FAULT(Fault));
  assert_param(IS_HRTIM_FAULTCTL(Enable));

  /* Configure fault channel */
  HRTIM_fltinr1 = HRTIMx->HRTIM_COMMON.FLTINxR1;
  HRTIM_fltinr2 = HRTIMx->HRTIM_COMMON.FLTINxR2;
  
  switch (Fault)
  {
    case HRTIM_FAULT_1:
    {
      HRTIM_fltinr1 &= ~HRTIM_FLTINR1_FLT1E;
      HRTIM_fltinr1 |= Enable;
    }
    break;
    case HRTIM_FAULT_2:
    {
      HRTIM_fltinr1 &= ~HRTIM_FLTINR1_FLT2E;
      HRTIM_fltinr1 |= (Enable<< 8);
    }
    break;
    case HRTIM_FAULT_3:
    {
      HRTIM_fltinr1 &= ~HRTIM_FLTINR1_FLT3E;
      HRTIM_fltinr1 |= (Enable << 16);
    }
    break;
    case HRTIM_FAULT_4:
    {
      HRTIM_fltinr1 &= ~HRTIM_FLTINR1_FLT4E; 
      HRTIM_fltinr1 |= (Enable << 24);
    }
    break;
    case HRTIM_FAULT_5:
    {
      HRTIM_fltinr2 &= ~HRTIM_FLTINR2_FLT5E;
      HRTIM_fltinr2 |= Enable;
    }
    break;
    default:
    break;
  }

  /* Update the HRTIMx registers */
  HRTIMx->HRTIM_COMMON.FLTINxR1 = HRTIM_fltinr1;
  HRTIMx->HRTIM_COMMON.FLTINxR2 = HRTIM_fltinr2;
}                              

/**
  * @brief  Configures both the ADC trigger register update source and the ADC
  *         trigger source.
  * @param  HRTIMx: pointer to HRTIMx peripheral
  * @param  ADC trigger: ADC trigger to configure
  *                    This parameter can be one of the following values:
  *                    @arg HRTIM_ADCTRIGGER_1: ADC trigger 1
  *                    @arg HRTIM_ADCTRIGGER_2: ADC trigger 2
  *                    @arg HRTIM_ADCTRIGGER_3: ADC trigger 3
  *                    @arg HRTIM_ADCTRIGGER_4: ADC trigger 4
  * @param  pADCTriggerCfg: pointer to the ADC trigger configuration structure
  * @retval None
  */
void HRTIM_ADCTriggerConfig(HRTIM_TypeDef * HRTIMx,
                                             uint32_t ADCTrigger,
                                             HRTIM_ADCTriggerCfgTypeDef* pADCTriggerCfg)
{
  uint32_t HRTIM_cr1;
  
  /* Check parameters */
  assert_param(IS_HRTIM_ADCTRIGGER(ADCTrigger));
  assert_param(IS_HRTIM_ADCTRIGGERUPDATE(pADCTriggerCfg->UpdateSource));

  /* Set the ADC trigger update source */
  HRTIM_cr1 = HRTIMx->HRTIM_COMMON.CR1;
  
  switch (ADCTrigger)
  {
    case HRTIM_ADCTRIGGER_1:
    {
      HRTIM_cr1 &= ~(HRTIM_CR1_ADC1USRC);
      HRTIM_cr1 |= pADCTriggerCfg->UpdateSource;
      
      /* Set the ADC trigger 1 source */
      HRTIMx->HRTIM_COMMON.ADC1R = pADCTriggerCfg->Trigger;
    }
    break;
    case HRTIM_ADCTRIGGER_2:
    {
      HRTIM_cr1 &= ~(HRTIM_CR1_ADC2USRC);
      HRTIM_cr1 |= (pADCTriggerCfg->UpdateSource << 3); 

      /* Set the ADC trigger 2 source */
      HRTIMx->HRTIM_COMMON.ADC2R = pADCTriggerCfg->Trigger;
    }
    break;
    case HRTIM_ADCTRIGGER_3:
    {
      HRTIM_cr1 &= ~(HRTIM_CR1_ADC3USRC);
      HRTIM_cr1 |= (pADCTriggerCfg->UpdateSource << 6); 
      
      /* Set the ADC trigger 3 source */
      HRTIMx->HRTIM_COMMON.ADC3R = pADCTriggerCfg->Trigger;
    }
    case HRTIM_ADCTRIGGER_4:
    {
      HRTIM_cr1 &= ~(HRTIM_CR1_ADC4USRC);
      HRTIM_cr1 |= (pADCTriggerCfg->UpdateSource << 9); 
      
      /* Set the ADC trigger 4 source */
      HRTIMx->HRTIM_COMMON.ADC4R = pADCTriggerCfg->Trigger;
    }
    break;
    default:
    break;
  }
  
  /* Update the HRTIMx registers */
  HRTIMx->HRTIM_COMMON.CR1 = HRTIM_cr1;
}


/**
  * @brief  Enables or disables the HRTIMx burst mode controller.
  * @param  HRTIMx: pointer to HRTIMx peripheral
  * @param  Enable: Burst mode controller enabling
  *                    This parameter can be one of the following values:
  *                    @arg HRTIM_BURSTMODECTL_ENABLED: Burst mode enabled
  *                    @arg HRTIM_BURSTMODECTL_DISABLED: Burst mode disabled
  * @retval None
  */
void HRTIM_BurstModeCtl(HRTIM_TypeDef * HRTIMx, uint32_t Enable)
{
  uint32_t HRTIM_bmcr;
  
  /* Check parameters */
  assert_param(IS_HRTIM_BURSTMODECTL(Enable));
  
  /* Enable/Disable the burst mode controller */
  HRTIM_bmcr = HRTIMx->HRTIM_COMMON.BMCR;
  HRTIM_bmcr &= ~(HRTIM_BMCR_BME);
  HRTIM_bmcr |= Enable;
  
  /* Update the HRTIMx registers */
  HRTIMx->HRTIM_COMMON.BMCR = HRTIM_bmcr;
}

/**
  * @brief  Triggers a software capture on the designed capture unit
  * @param  HRTIMx: pointer to HRTIMx peripheral
  * @param  TimerIdx: Timer index
  *                   This parameter can be one of the following values:
  *                   @arg 0x0 to 0x4 for timers A to E 
  * @param  CaptureUnit: Capture unit to trig
  *                    This parameter can be one of the following values: 
  *                    @arg HRTIM_CAPTUREUNIT_1: Capture unit 1
  *                    @arg HRTIM_CAPTUREUNIT_2: Capture unit 2
  * @retval None
  * @note The 'software capture' bit in the capure configuration register is
  *       automatically reset by hardware
  */
void HRTIM_SoftwareCapture(HRTIM_TypeDef * HRTIMx,
                                            uint32_t TimerIdx,
                                            uint32_t CaptureUnit)
{
  /* Check parameters */
  assert_param(IS_HRTIM_TIMING_UNIT(TimerIdx));
  assert_param(IS_HRTIM_CAPTUREUNIT(CaptureUnit));
  
  /* Force a software capture on concerned capture unit */
  switch (CaptureUnit)
  {
    case HRTIM_CAPTUREUNIT_1:
    {
      HRTIMx->HRTIM_TIMERx[TimerIdx].CPT1xCR |= HRTIM_CPT1CR_SWCPT;
    }
    break;
    case HRTIM_CAPTUREUNIT_2:
    {
      HRTIMx->HRTIM_TIMERx[TimerIdx].CPT2xCR |= HRTIM_CPT2CR_SWCPT;
    }
    break;
    default:
    break;
  }
}

/**
  * @brief  Triggers the update of the registers of one or several timers
  * @param  HRTIMx: pointer to HRTIMx peripheral
  * @param  TimersToUpdate: timers concerned with the software register update
  *                   This parameter can be any combination of the following values:
  *                   @arg HRTIM_TIMERUPDATE_MASTER 
  *                   @arg HRTIM_TIMERUPDATE_A 
  *                   @arg HRTIM_TIMERUPDATE_B 
  *                   @arg HRTIM_TIMERUPDATE_C 
  *                   @arg HRTIM_TIMERUPDATE_D 
  *                   @arg HRTIM_TIMERUPDATE_E 
  * @retval None
  * @note The 'software update' bits in the HRTIMx control register 2 register are
  *       automatically reset by hardware
  */
void HRTIM_SoftwareUpdate(HRTIM_TypeDef * HRTIMx,
                                           uint32_t TimersToUpdate)
{
  /* Check parameters */
  assert_param(IS_HRTIM_TIMERUPDATE(TimersToUpdate));
  
  /* Force timer(s) registers update */
  HRTIMx->HRTIM_COMMON.CR2 |= TimersToUpdate;
  
}

/**
  * @brief  Triggers the reset of one or several timers
  * @param  HRTIMx: pointer to HRTIMx peripheral
  * @param  TimersToUpdate: timers concerned with the software counter reset
  *                   This parameter can be any combination of the following values:
  *                   @arg HRTIM_TIMER_MASTER 
  *                   @arg HRTIM_TIMER_A 
  *                   @arg HRTIM_TIMER_B 
  *                   @arg HRTIM_TIMER_C 
  *                   @arg HRTIM_TIMER_D 
  *                   @arg HRTIM_TIMER_E 
  * @retval None
  * @note The 'software reset' bits in the HRTIMx control register 2  are
  *       automatically reset by hardware
  */
void HRTIM_SoftwareReset(HRTIM_TypeDef * HRTIMx,
                                          uint32_t TimersToReset)
{
  /* Check parameters */
  assert_param(IS_HRTIM_TIMERRESET(TimersToReset));
  
  /* Force timer(s) registers update */
  HRTIMx->HRTIM_COMMON.CR2 |= TimersToReset;
 
}

/**
  * @brief  Forces the timer output to its active or inactive state 
  * @param  HRTIMx: pointer to HRTIMx peripheral
  * @param  TimerIdx: Timer index
  *                   This parameter can be one of the following values:
  *                   @arg 0x0 to 0x4 for timers A to E 
  * @param  Output: Timer output
  *                    This parameter can be one of the following values:
  *                    @arg HRTIM_OUTPUT_TA1: Timer A - Output 1
  *                    @arg HRTIM_OUTPUT_TA2: Timer A - Output 2
  *                    @arg HRTIM_OUTPUT_TB1: Timer B - Output 1
  *                    @arg HRTIM_OUTPUT_TB2: Timer B - Output 2
  *                    @arg HRTIM_OUTPUT_TC1: Timer C - Output 1
  *                    @arg HRTIM_OUTPUT_TC2: Timer C - Output 2
  *                    @arg HRTIM_OUTPUT_TD1: Timer D - Output 1
  *                    @arg HRTIM_OUTPUT_TD2: Timer D - Output 2
  *                    @arg HRTIM_OUTPUT_TE1: Timer E - Output 1
  *                    @arg HRTIM_OUTPUT_TE2: Timer E - Output 2
  * @param OutputLevel: indicates whether the output is forced to its active or inactive state
  *                    This parameter can be one of the following values:
  *                    @arg HRTIM_OUTPUTLEVEL_ACTIVE: output is forced to its active state
  *                    @arg HRTIM_OUTPUTLEVEL_INACTIVE: output is forced to its inactive state
  * @retval None
  * @note The 'software set/reset trigger' bit in the output set/reset registers 
  *       is automatically reset by hardware
  */
void HRTIM_WaveformSetOutputLevel(HRTIM_TypeDef * HRTIMx,
                                                   uint32_t TimerIdx,
                                                   uint32_t Output,
                                                   uint32_t OutputLevel)
{
  /* Check parameters */
  assert_param(IS_HRTIM_TIMER_OUTPUT(TimerIdx, Output));
  assert_param(IS_HRTIM_OUTPUTLEVEL(OutputLevel));

  /* Force timer output level */
  switch (Output)
  {
    case HRTIM_OUTPUT_TA1:
    case HRTIM_OUTPUT_TB1:
    case HRTIM_OUTPUT_TC1:
    case HRTIM_OUTPUT_TD1:
    case HRTIM_OUTPUT_TE1:
    {
      if (OutputLevel == HRTIM_OUTPUTLEVEL_ACTIVE)
      {
        /* Force output to its active state */
        HRTIMx->HRTIM_TIMERx[TimerIdx].SETx1R |= HRTIM_SET1R_SST;
      }
      else
      {
        /* Force output to its inactive state */
        HRTIMx->HRTIM_TIMERx[TimerIdx].RSTx1R |= HRTIM_RST1R_SRT;
      }
    }
    break;
    case HRTIM_OUTPUT_TA2:
    case HRTIM_OUTPUT_TB2:
    case HRTIM_OUTPUT_TC2:
    case HRTIM_OUTPUT_TD2:
    case HRTIM_OUTPUT_TE2:
    {
      if (OutputLevel == HRTIM_OUTPUTLEVEL_ACTIVE)
      {
        /* Force output to its active state */
        HRTIMx->HRTIM_TIMERx[TimerIdx].SETx2R |= HRTIM_SET2R_SST;
      }
      else
      {
        /* Force output to its inactive state */
        HRTIMx->HRTIM_TIMERx[TimerIdx].RSTx2R |= HRTIM_RST2R_SRT;
      }
    }
    break;
    default:
    break;
  } 
}


/**
  * @}
  */

/** @defgroup HRTIM_Group4 Peripheral State methods 
 *  @brief   Peripheral State functions 
 *
@verbatim   
 ===============================================================================
                      ##### Peripheral State methods #####
 ===============================================================================  
    [..]
    This subsection permit to get in run-time the status of the peripheral 
    and the data flow.

@endverbatim
  * @{
  */

/**
  * @brief  Returns actual value of the capture register of the designated capture unit 
  * @param  HRTIMx: pointer to HRTIMx peripheral
  * @param  TimerIdx: Timer index
  *                   This parameter can be one of the following values:
  *                   @arg 0x0 to 0x4 for timers A to E 
  * @param  CaptureUnit: Capture unit to trig
  *                    This parameter can be one of the following values: 
  *                    @arg HRTIM_CAPTUREUNIT_1: Capture unit 1
  *                    @arg HRTIM_CAPTUREUNIT_2: Capture unit 2
  * @retval Captured value
  */
uint32_t HRTIM_GetCapturedValue(HRTIM_TypeDef * HRTIMx,
                                    uint32_t TimerIdx,
                                    uint32_t CaptureUnit)
{
  uint32_t captured_value = 0;
  
  /* Check parameters */
  assert_param(IS_HRTIM_TIMING_UNIT(TimerIdx));
  assert_param(IS_HRTIM_CAPTUREUNIT(CaptureUnit));

  /* Read captured value */
  switch (CaptureUnit)
  {
    case HRTIM_CAPTUREUNIT_1:
    {
      captured_value = HRTIMx->HRTIM_TIMERx[TimerIdx].CPT1xR;
    }
    break;
    case HRTIM_CAPTUREUNIT_2:
    {
      captured_value = HRTIMx->HRTIM_TIMERx[TimerIdx].CPT2xR;
    }
    break;
    default:
    break;
  }
  
  return captured_value; 
}

/**
  * @brief  Returns actual level (active or inactive) of the designated output 
  * @param  HRTIMx: pointer to HRTIMx peripheral
  * @param  TimerIdx: Timer index
  *                   This parameter can be one of the following values:
  *                   @arg 0x0 to 0x4 for timers A to E 
  * @param  Output: Timer output
  *                    This parameter can be one of the following values:
  *                    @arg HRTIM_OUTPUT_TA1: Timer A - Output 1
  *                    @arg HRTIM_OUTPUT_TA2: Timer A - Output 2
  *                    @arg HRTIM_OUTPUT_TB1: Timer B - Output 1
  *                    @arg HRTIM_OUTPUT_TB2: Timer B - Output 2
  *                    @arg HRTIM_OUTPUT_TC1: Timer C - Output 1
  *                    @arg HRTIM_OUTPUT_TC2: Timer C - Output 2
  *                    @arg HRTIM_OUTPUT_TD1: Timer D - Output 1
  *                    @arg HRTIM_OUTPUT_TD2: Timer D - Output 2
  *                    @arg HRTIM_OUTPUT_TE1: Timer E - Output 1
  *                    @arg HRTIM_OUTPUT_TE2: Timer E - Output 2
  * @retval Output level
  * @note Returned output level is taken before the output stage (chopper, 
  *        polarity).
  */
uint32_t HRTIM_WaveformGetOutputLevel(HRTIM_TypeDef * HRTIMx,
                                          uint32_t TimerIdx,
                                          uint32_t Output)
{
  uint32_t output_level = HRTIM_OUTPUTLEVEL_INACTIVE;
  
  /* Check parameters */
  assert_param(IS_HRTIM_TIMER_OUTPUT(TimerIdx, Output));
  
  /* Read the output level */
  switch (Output)
  {
    case HRTIM_OUTPUT_TA1:
    case HRTIM_OUTPUT_TB1:
    case HRTIM_OUTPUT_TC1:
    case HRTIM_OUTPUT_TD1:
    case HRTIM_OUTPUT_TE1:
    {
      if ((HRTIMx->HRTIM_TIMERx[TimerIdx].TIMxISR & HRTIM_TIMISR_O1CPY) != RESET)
      {
        output_level = HRTIM_OUTPUTLEVEL_ACTIVE;
      }
      else
      {
        output_level = HRTIM_OUTPUTLEVEL_INACTIVE;
      }
    }
    break;
    case HRTIM_OUTPUT_TA2:
    case HRTIM_OUTPUT_TB2:
    case HRTIM_OUTPUT_TC2:
    case HRTIM_OUTPUT_TD2:
    case HRTIM_OUTPUT_TE2:
    {
      if ((HRTIMx->HRTIM_TIMERx[TimerIdx].TIMxISR & HRTIM_TIMISR_O2CPY) != RESET)
      {
        output_level = HRTIM_OUTPUTLEVEL_ACTIVE;
      }
      else
      {
        output_level = HRTIM_OUTPUTLEVEL_INACTIVE;
      }
    }
    break;
    default:
    break;
  }
  
  return output_level; 
}

/**
  * @brief  Returns actual state (RUN, IDLE, FAULT) of the designated output 
  * @param  HRTIMx: pointer to HRTIMx peripheral
  * @param  TimerIdx: Timer index
  *                   This parameter can be one of the following values:
  *                   @arg 0x0 to 0x4 for timers A to E 
  * @param  Output: Timer output
  *                    This parameter can be one of the following values:
  *                    @arg HRTIM_OUTPUT_TA1: Timer A - Output 1
  *                    @arg HRTIM_OUTPUT_TA2: Timer A - Output 2
  *                    @arg HRTIM_OUTPUT_TB1: Timer B - Output 1
  *                    @arg HRTIM_OUTPUT_TB2: Timer B - Output 2
  *                    @arg HRTIM_OUTPUT_TC1: Timer C - Output 1
  *                    @arg HRTIM_OUTPUT_TC2: Timer C - Output 2
  *                    @arg HRTIM_OUTPUT_TD1: Timer D - Output 1
  *                    @arg HRTIM_OUTPUT_TD2: Timer D - Output 2
  *                    @arg HRTIM_OUTPUT_TE1: Timer E - Output 1
  *                    @arg HRTIM_OUTPUT_TE2: Timer E - Output 2
  * @retval Output state
  */
uint32_t HRTIM_WaveformGetOutputState(HRTIM_TypeDef * HRTIMx,
                                          uint32_t TimerIdx,
                                          uint32_t Output)
{
  uint32_t output_bit = 0;
  uint32_t output_state = HRTIM_OUTPUTSTATE_IDLE;
  
  /* Check parameters */
  assert_param(IS_HRTIM_TIMER_OUTPUT(TimerIdx, Output));
  
  /* Set output state according to output control status and output disable status */
  switch (Output)
  {
    case HRTIM_OUTPUT_TA1:
    {
      output_bit = HRTIM_OENR_TA1OEN;
    }
    break;
    case HRTIM_OUTPUT_TA2:
    {
      output_bit = HRTIM_OENR_TA2OEN;
    }
    break;
    case HRTIM_OUTPUT_TB1:
    {
      output_bit = HRTIM_OENR_TB1OEN;
    }
    break;
    case HRTIM_OUTPUT_TB2:
    {
      output_bit = HRTIM_OENR_TB2OEN;
    }
    break;
    case HRTIM_OUTPUT_TC1:
    {
      output_bit = HRTIM_OENR_TC1OEN;
    }
    break;
    case HRTIM_OUTPUT_TC2:
    {
      output_bit = HRTIM_OENR_TC2OEN;
    }
    break;
    case HRTIM_OUTPUT_TD1:
    {
      output_bit = HRTIM_OENR_TD1OEN;
    }
    break;
    case HRTIM_OUTPUT_TD2:
    {
      output_bit = HRTIM_OENR_TD2OEN;
    }
    break;
    case HRTIM_OUTPUT_TE1:
    {
      output_bit = HRTIM_OENR_TE1OEN;
    }
    break;
    case HRTIM_OUTPUT_TE2:
    {
      output_bit = HRTIM_OENR_TE2OEN;
    }
    break;
    default:
    break;
  }
  
  if ((HRTIMx->HRTIM_COMMON.OENR & output_bit) != RESET)
  {
    /* Output is enabled: output in RUN state (whatever ouput disable status is)*/
    output_state = HRTIM_OUTPUTSTATE_RUN;
  }
  else
  {
    if ((HRTIMx->HRTIM_COMMON.ODSR & output_bit) != RESET)
    {
    /* Output is disabled: output in FAULT state */
      output_state = HRTIM_OUTPUTSTATE_FAULT;
    }
    else
    {
      /* Output is disabled: output in IDLE state */
      output_state = HRTIM_OUTPUTSTATE_IDLE;
    }
  }
  
  return(output_state);  
}

/**
  * @brief  Returns the level (active or inactive) of the designated output 
  *         when the delayed protection was triggered 
  * @param  HRTIMx: pointer to HRTIMx peripheral
  * @param  TimerIdx: Timer index
  *                   This parameter can be one of the following values:
  *                   @arg 0x0 to 0x4 for timers A to E 
  * @param  Output: Timer output
  *                    This parameter can be one of the following values:
  *                    @arg HRTIM_OUTPUT_TA1: Timer A - Output 1
  *                    @arg HRTIM_OUTPUT_TA2: Timer A - Output 2
  *                    @arg HRTIM_OUTPUT_TB1: Timer B - Output 1
  *                    @arg HRTIM_OUTPUT_TB2: Timer B - Output 2
  *                    @arg HRTIM_OUTPUT_TC1: Timer C - Output 1
  *                    @arg HRTIM_OUTPUT_TC2: Timer C - Output 2
  *                    @arg HRTIM_OUTPUT_TD1: Timer D - Output 1
  *                    @arg HRTIM_OUTPUT_TD2: Timer D - Output 2
  *                    @arg HRTIM_OUTPUT_TD1: Timer E - Output 1
  *                    @arg HRTIM_OUTPUT_TD2: Timer E - Output 2
  * @retval Delayed protection status 
  */
uint32_t HRTIM_GetDelayedProtectionStatus(HRTIM_TypeDef * HRTIMx,
                                              uint32_t TimerIdx,
                                              uint32_t Output)
{
  uint32_t delayed_protection_status = HRTIM_OUTPUTLEVEL_INACTIVE;
  
  /* Check parameters */
  assert_param(IS_HRTIM_TIMER_OUTPUT(TimerIdx, Output));

  /* Read the delayed protection status */
  switch (Output)
  {
    case HRTIM_OUTPUT_TA1:
    case HRTIM_OUTPUT_TB1:
    case HRTIM_OUTPUT_TC1:
    case HRTIM_OUTPUT_TD1:
    case HRTIM_OUTPUT_TE1:
    {
      if ((HRTIMx->HRTIM_TIMERx[TimerIdx].TIMxISR & HRTIM_TIMISR_O1STAT) != RESET)
      {
        /* Output 1 was active when the delayed idle protection was triggered */
        delayed_protection_status = HRTIM_OUTPUTLEVEL_ACTIVE;
      }
      else
      {
        /* Output 1 was inactive when the delayed idle protection was triggered */
        delayed_protection_status = HRTIM_OUTPUTLEVEL_INACTIVE;
      }
    }
    break;
    case HRTIM_OUTPUT_TA2:
    case HRTIM_OUTPUT_TB2:
    case HRTIM_OUTPUT_TC2:
    case HRTIM_OUTPUT_TD2:
    case HRTIM_OUTPUT_TE2:
    {
      if ((HRTIMx->HRTIM_TIMERx[TimerIdx].TIMxISR & HRTIM_TIMISR_O2STAT) != RESET)
      {
        /* Output 2 was active when the delayed idle protection was triggered */
        delayed_protection_status = HRTIM_OUTPUTLEVEL_ACTIVE;
      }
      else
      {
        /* Output 2 was inactive when the delayed idle protection was triggered */
        delayed_protection_status = HRTIM_OUTPUTLEVEL_INACTIVE;
      }
    }
    break;
    default:
    break;
  }
  
  return delayed_protection_status;
}

/**
  * @brief  Returns the actual status (active or inactive) of the burst mode controller 
  * @param  HRTIMx: pointer to HRTIMx peripheral
  * @retval Burst mode controller status 
  */
uint32_t HRTIM_GetBurstStatus(HRTIM_TypeDef * HRTIMx)
{
  uint32_t burst_mode_status;

  /* Read burst mode status */
  burst_mode_status = (HRTIMx->HRTIM_COMMON.BMCR & HRTIM_BMCR_BMSTAT);
  
  return burst_mode_status; 
}

/**
  * @brief  Indicates on which output the signal is currently active (when the
  *         push pull mode is enabled)
  * @param  HRTIMx: pointer to HRTIMx peripheral
  * @param  TimerIdx: Timer index
  *                   This parameter can be one of the following values:
  *                   @arg 0x0 to 0x4 for timers A to E 
  * @retval Burst mode controller status 
  */
uint32_t HRTIM_GetCurrentPushPullStatus(HRTIM_TypeDef * HRTIMx,
                                            uint32_t TimerIdx)
{
  uint32_t current_pushpull_status;

   /* Check the parameters */
  assert_param(IS_HRTIM_TIMING_UNIT(TimerIdx));

  /* Read current push pull status */
  current_pushpull_status = (HRTIMx->HRTIM_TIMERx[TimerIdx].TIMxISR & HRTIM_TIMISR_CPPSTAT);
  
  return current_pushpull_status; 
}


/**
  * @brief  Indicates on which output the signal was applied, in push-pull mode
            balanced fault mode or delayed idle mode, when the protection was triggered
  * @param  HRTIMx: pointer to HRTIMx peripheral
  * @param  TimerIdx: Timer index
  *                   This parameter can be one of the following values:
  *                   @arg 0x0 to 0x4 for timers A to E 
  * @retval Idle Push Pull Status 
  */
uint32_t HRTIM_GetIdlePushPullStatus(HRTIM_TypeDef * HRTIMx,
                                         uint32_t TimerIdx)
{
  uint32_t idle_pushpull_status;

   /* Check the parameters */
  assert_param(IS_HRTIM_TIMING_UNIT(TimerIdx));

  /* Read current push pull status */
  idle_pushpull_status = (HRTIMx->HRTIM_TIMERx[TimerIdx].TIMxISR & HRTIM_TIMISR_IPPSTAT);
  
  return idle_pushpull_status; 
}

/**
  * @brief  Configures the master timer time base
  * @param  HRTIMx: pointer to HRTIMx peripheral
  * @retval None
  */
void  HRTIM_MasterBase_Config(HRTIM_TypeDef * HRTIMx, HRTIM_BaseInitTypeDef* HRTIM_BaseInitStruct)
{  
  /* Set the prescaler ratio */
  HRTIMx->HRTIM_MASTER.MCR &= (uint32_t) ~(HRTIM_MCR_CK_PSC);
  HRTIMx->HRTIM_MASTER.MCR  |= (uint32_t)HRTIM_BaseInitStruct->PrescalerRatio;
  
  /* Set the operating mode */
  HRTIMx->HRTIM_MASTER.MCR  &= (uint32_t) ~(HRTIM_MCR_CONT | HRTIM_MCR_RETRIG);
  HRTIMx->HRTIM_MASTER.MCR  |= (uint32_t)HRTIM_BaseInitStruct->Mode;
  
  /* Update the HRTIMx registers */
  HRTIMx->HRTIM_MASTER.MPER = HRTIM_BaseInitStruct->Period;
  HRTIMx->HRTIM_MASTER.MREP = HRTIM_BaseInitStruct->RepetitionCounter;
}

/**
  * @brief  Configures timing unit (timer A to timer E) time base
  * @param  HRTIMx: pointer to HRTIMx peripheral
  * @param  TimerIdx: Timer index
  * @retval None
  */
void HRTIM_TimingUnitBase_Config(HRTIM_TypeDef * HRTIMx, uint32_t TimerIdx, HRTIM_BaseInitTypeDef* HRTIM_BaseInitStruct)
{   
  /* Set the prescaler ratio */
  HRTIMx->HRTIM_TIMERx[TimerIdx].TIMxCR &= (uint32_t) ~(HRTIM_TIMCR_CK_PSC);
  HRTIMx->HRTIM_TIMERx[TimerIdx].TIMxCR |= (uint32_t)HRTIM_BaseInitStruct->PrescalerRatio;

  /* Set the operating mode */
  HRTIMx->HRTIM_TIMERx[TimerIdx].TIMxCR &= (uint32_t) ~(HRTIM_TIMCR_CONT | HRTIM_TIMCR_RETRIG);
  HRTIMx->HRTIM_TIMERx[TimerIdx].TIMxCR |= (uint32_t)HRTIM_BaseInitStruct->Mode;
  
  /* Update the HRTIMx registers */
  HRTIMx->HRTIM_TIMERx[TimerIdx].PERxR = HRTIM_BaseInitStruct->Period;
  HRTIMx->HRTIM_TIMERx[TimerIdx].REPxR = HRTIM_BaseInitStruct->RepetitionCounter;
}

/**
  * @brief  Configures the master timer in waveform mode
  * @param  HRTIMx: pointer to HRTIMx peripheral
  * @param  TimerIdx: Timer index
  * @param  pTimerInit: pointer to the timer initialization data structure
  * @retval None
  */
void  HRTIM_MasterWaveform_Config(HRTIM_TypeDef * HRTIMx, 
                                HRTIM_TimerInitTypeDef * pTimerInit)
{
  uint32_t HRTIM_mcr;
  uint32_t HRTIM_bmcr;
  
  /* Configure master timer */
  HRTIM_mcr = HRTIMx->HRTIM_MASTER.MCR;
  HRTIM_bmcr = HRTIMx->HRTIM_COMMON.BMCR;
  
  /* Enable/Disable the half mode */
  HRTIM_mcr &= ~(HRTIM_MCR_HALF);
  HRTIM_mcr |= pTimerInit->HalfModeEnable;
  
  /* Enable/Disable the timer start upon synchronization event reception */
  HRTIM_mcr &= ~(HRTIM_MCR_SYNCSTRTM);
  HRTIM_mcr |= pTimerInit->StartOnSync;
 
  /* Enable/Disable the timer reset upon synchronization event reception */
  HRTIM_mcr &= ~(HRTIM_MCR_SYNCRSTM);
  HRTIM_mcr |= pTimerInit->ResetOnSync;
  
  /* Enable/Disable the DAC synchronization event generation */
  HRTIM_mcr &= ~(HRTIM_MCR_DACSYNC);
  HRTIM_mcr |= pTimerInit->DACSynchro;
  
  /* Enable/Disable preload mechanism for timer registers */
  HRTIM_mcr &= ~(HRTIM_MCR_PREEN);
  HRTIM_mcr |= pTimerInit->PreloadEnable;
  
  /* Master timer registers update handling */
  HRTIM_mcr &= ~(HRTIM_MCR_BRSTDMA);
  HRTIM_mcr |= (pTimerInit->UpdateGating << 2);
  
  /* Enable/Disable registers update on repetition */
  HRTIM_mcr &= ~(HRTIM_MCR_MREPU);
  HRTIM_mcr |= pTimerInit->RepetitionUpdate;
  
  /* Set the timer burst mode */
  HRTIM_bmcr &= ~(HRTIM_BMCR_MTBM);
  HRTIM_bmcr |= pTimerInit->BurstMode;

  /* Update the HRTIMx registers */
  HRTIMx->HRTIM_MASTER.MCR  = HRTIM_mcr;
  HRTIMx->HRTIM_COMMON.BMCR = HRTIM_bmcr;
  
}

/**
  * @brief  Configures timing unit (timer A to timer E) in waveform mode 
  * @param  HRTIMx: pointer to HRTIMx peripheral
  * @param  TimerIdx: Timer index
  * @param  pTimerInit: pointer to the timer initialization data structure
  * @retval None
  */
void HRTIM_TimingUnitWaveform_Config(HRTIM_TypeDef * HRTIMx, 
                                    uint32_t TimerIdx, 
                                    HRTIM_TimerInitTypeDef * pTimerInit)
{
  uint32_t HRTIM_timcr;
  uint32_t HRTIM_bmcr;
  
  /* Configure timing unit */
  HRTIM_timcr = HRTIMx->HRTIM_TIMERx[TimerIdx].TIMxCR;
  HRTIM_bmcr = HRTIMx->HRTIM_COMMON.BMCR;
  
  /* Enable/Disable the half mode */
  HRTIM_timcr &= ~(HRTIM_TIMCR_HALF);
  HRTIM_timcr |= pTimerInit->HalfModeEnable;
  
  /* Enable/Disable the timer start upon synchronization event reception */
  HRTIM_timcr &= ~(HRTIM_TIMCR_SYNCSTRT);
  HRTIM_timcr |= pTimerInit->StartOnSync;
 
  /* Enable/Disable the timer reset upon synchronization event reception */
  HRTIM_timcr &= ~(HRTIM_TIMCR_SYNCRST);
  HRTIM_timcr |= pTimerInit->ResetOnSync;
  
  /* Enable/Disable the DAC synchronization event generation */
  HRTIM_timcr &= ~(HRTIM_TIMCR_DACSYNC);
  HRTIM_timcr |= pTimerInit->DACSynchro;
  
  /* Enable/Disable preload mechanism for timer registers */
  HRTIM_timcr &= ~(HRTIM_TIMCR_PREEN);
  HRTIM_timcr |= pTimerInit->PreloadEnable;
  
  /* Timing unit registers update handling */
  HRTIM_timcr &= ~(HRTIM_TIMCR_UPDGAT);
  HRTIM_timcr |= pTimerInit->UpdateGating;
  
  /* Enable/Disable registers update on repetition */
  HRTIM_timcr &= ~(HRTIM_TIMCR_TREPU);
  if (pTimerInit->RepetitionUpdate == HRTIM_UPDATEONREPETITION_ENABLED)
  {
    HRTIM_timcr |= HRTIM_TIMCR_TREPU;
  }

  /* Set the timer burst mode */
  switch (TimerIdx)
  {
    case HRTIM_TIMERINDEX_TIMER_A:
    {
      HRTIM_bmcr &= ~(HRTIM_BMCR_TABM);
      HRTIM_bmcr |= ( pTimerInit->BurstMode << 1);
    }
    break;
    case HRTIM_TIMERINDEX_TIMER_B:
    {
      HRTIM_bmcr &= ~(HRTIM_BMCR_TBBM);
      HRTIM_bmcr |= ( pTimerInit->BurstMode << 2);
    }
    break;
    case HRTIM_TIMERINDEX_TIMER_C:
    {
      HRTIM_bmcr &= ~(HRTIM_BMCR_TCBM);
      HRTIM_bmcr |= ( pTimerInit->BurstMode << 3);
    }
    break;
    case HRTIM_TIMERINDEX_TIMER_D:
    {
      HRTIM_bmcr &= ~(HRTIM_BMCR_TDBM);
      HRTIM_bmcr |= ( pTimerInit->BurstMode << 4);
    }
    break;
    case HRTIM_TIMERINDEX_TIMER_E:
    {
      HRTIM_bmcr &= ~(HRTIM_BMCR_TEBM);
      HRTIM_bmcr |= ( pTimerInit->BurstMode << 5);
    }
    break;
    default:
    break;
  }
  
  /* Update the HRTIMx registers */
  HRTIMx->HRTIM_TIMERx[TimerIdx].TIMxCR = HRTIM_timcr;
  HRTIMx->HRTIM_COMMON.BMCR = HRTIM_bmcr;
}

/**
  * @brief  Configures a compare unit 
  * @param  HRTIMx: pointer to HRTIMx peripheral
  * @param  TimerIdx: Timer index
  * @param  CompareUnit: Compare unit identifier
  * @param  pCompareCfg: pointer to the compare unit configuration data structure
  * @retval None
  */
void  HRTIM_CompareUnitConfig(HRTIM_TypeDef * HRTIMx,
                              uint32_t TimerIdx,
                              uint32_t CompareUnit,
                              HRTIM_CompareCfgTypeDef * pCompareCfg)
{
  if (TimerIdx == HRTIM_TIMERINDEX_MASTER)
  {
    /* Configure the compare unit of the master timer */
    switch (CompareUnit)
    {
      case HRTIM_COMPAREUNIT_1:
      {
        HRTIMx->HRTIM_MASTER.MCMP1R = pCompareCfg->CompareValue;
      }
      break;
      case HRTIM_COMPAREUNIT_2:
      {
        HRTIMx->HRTIM_MASTER.MCMP2R = pCompareCfg->CompareValue;
      }
      break;
      case HRTIM_COMPAREUNIT_3:
      {
        HRTIMx->HRTIM_MASTER.MCMP3R = pCompareCfg->CompareValue;
      }
      break;
      case HRTIM_COMPAREUNIT_4:
      {
        HRTIMx->HRTIM_MASTER.MCMP4R = pCompareCfg->CompareValue;
      }
      break;
      default:
      break;
    }
  }
  else
  {
    /* Configure the compare unit of the timing unit */
    switch (CompareUnit)
    {
      case HRTIM_COMPAREUNIT_1:
      {
        HRTIMx->HRTIM_TIMERx[TimerIdx].CMP1xR = pCompareCfg->CompareValue;
      }
      break;
      case HRTIM_COMPAREUNIT_2:
      {
        HRTIMx->HRTIM_TIMERx[TimerIdx].CMP2xR = pCompareCfg->CompareValue;
      }
      break;
      case HRTIM_COMPAREUNIT_3:
      {
        HRTIMx->HRTIM_TIMERx[TimerIdx].CMP3xR = pCompareCfg->CompareValue;
      }
      break;
      case HRTIM_COMPAREUNIT_4:
      {
        HRTIMx->HRTIM_TIMERx[TimerIdx].CMP4xR = pCompareCfg->CompareValue;
      }
      break;
      default:
      break;
    }
  }
}

/**
  * @brief  Configures a capture unit 
  * @param  HRTIMx: pointer to HRTIMx peripheral
  * @param  TimerIdx: Timer index
  * @param  CaptureUnit: Capture unit identifier
  * @param  pCaptureCfg: pointer to the compare unit configuration data structure
  * @retval None
  */
void HRTIM_CaptureUnitConfig(HRTIM_TypeDef * HRTIMx,
                             uint32_t TimerIdx,
                             uint32_t CaptureUnit,
                             uint32_t Event)
{
  uint32_t CaptureTrigger = HRTIM_CAPTURETRIGGER_EEV_1;
  
  switch (Event)
  {
    case HRTIM_EVENT_1:
    {
      CaptureTrigger = HRTIM_CAPTURETRIGGER_EEV_1;
    }
    break;
    case HRTIM_EVENT_2:
    {
      CaptureTrigger = HRTIM_CAPTURETRIGGER_EEV_2;
    }
    break;
    case HRTIM_EVENT_3:
    {
      CaptureTrigger = HRTIM_CAPTURETRIGGER_EEV_3;
    }
    break;
    case HRTIM_EVENT_4:
    {
      CaptureTrigger = HRTIM_CAPTURETRIGGER_EEV_4;
    }
    break;
    case HRTIM_EVENT_5:
    {
      CaptureTrigger = HRTIM_CAPTURETRIGGER_EEV_5;
    }
    break;
    case HRTIM_EVENT_6:
    {
      CaptureTrigger = HRTIM_CAPTURETRIGGER_EEV_6;
    }
    break;
    case HRTIM_EVENT_7:
    {
      CaptureTrigger = HRTIM_CAPTURETRIGGER_EEV_7;
    }
    break;
    case HRTIM_EVENT_8:
    {
      CaptureTrigger = HRTIM_CAPTURETRIGGER_EEV_8;
    }
    break;
    case HRTIM_EVENT_9:
    {
      CaptureTrigger = HRTIM_CAPTURETRIGGER_EEV_9;
    }
    break;
    case HRTIM_EVENT_10:
    {
      CaptureTrigger = HRTIM_CAPTURETRIGGER_EEV_10;
    }
    break;
    default:
    break;  
    
  }  
  switch (CaptureUnit)
  {
    case HRTIM_CAPTUREUNIT_1:
    {
      HRTIMx->HRTIM_TIMERx[TimerIdx].CPT1xCR = CaptureTrigger;
    }
    break;
    case HRTIM_CAPTUREUNIT_2:
    {
      HRTIMx->HRTIM_TIMERx[TimerIdx].CPT2xCR = CaptureTrigger;
    }
    break;
    default:
    break;  
  }
}

/**
  * @brief  Configures the output of a timing unit 
  * @param  HRTIMx: pointer to HRTIMx peripheral
  * @param  TimerIdx: Timer index
  * @param  Output: timing unit output identifier
  * @param  pOutputCfg: pointer to the output configuration data structure
  * @retval None
  */
void  HRTIM_OutputConfig(HRTIM_TypeDef * HRTIMx,
                         uint32_t TimerIdx,
                         uint32_t Output,
                         HRTIM_OutputCfgTypeDef * pOutputCfg)
{
  uint32_t HRTIM_outr;
  uint32_t shift = 0;
  
  HRTIM_outr = HRTIMx->HRTIM_TIMERx[TimerIdx].OUTxR;
  
  switch (Output)
  {
    case HRTIM_OUTPUT_TA1:
    case HRTIM_OUTPUT_TB1:
    case HRTIM_OUTPUT_TC1:
    case HRTIM_OUTPUT_TD1:
    case HRTIM_OUTPUT_TE1:
    {
      /* Set the output set/reset crossbar */
      HRTIMx->HRTIM_TIMERx[TimerIdx].SETx1R = pOutputCfg->SetSource;
      HRTIMx->HRTIM_TIMERx[TimerIdx].RSTx1R = pOutputCfg->ResetSource;
      
      shift = 0;
    }
    break;
    case HRTIM_OUTPUT_TA2:
    case HRTIM_OUTPUT_TB2:
    case HRTIM_OUTPUT_TC2:
    case HRTIM_OUTPUT_TD2:
    case HRTIM_OUTPUT_TE2:
    {
      /* Set the output set/reset crossbar */
      HRTIMx->HRTIM_TIMERx[TimerIdx].SETx2R = pOutputCfg->SetSource;
      HRTIMx->HRTIM_TIMERx[TimerIdx].RSTx2R = pOutputCfg->ResetSource;

      shift = 16;
    }
    break;
    default:
    break;
  }
  
  /* Clear output config */
  HRTIM_outr &= ~((HRTIM_OUTR_POL1 |
                   HRTIM_OUTR_IDLM1 |
                   HRTIM_OUTR_IDLES1|
                   HRTIM_OUTR_FAULT1|
                   HRTIM_OUTR_CHP1 |
                   HRTIM_OUTR_DIDL1)  << shift);
  
  /* Set the polarity */
  HRTIM_outr |= (pOutputCfg->Polarity << shift);
  
  /* Set the IDLE mode */
  HRTIM_outr |= (pOutputCfg->IdleMode << shift);
  
  /* Set the IDLE state */
  HRTIM_outr |= (pOutputCfg->IdleState << shift);
  
  /* Set the FAULT state */
  HRTIM_outr |= (pOutputCfg->FaultState << shift);
  
  /* Set the chopper mode */
  HRTIM_outr |= (pOutputCfg->ChopperModeEnable << shift);

  /* Set the burst mode entry mode */
  HRTIM_outr |= (pOutputCfg->BurstModeEntryDelayed << shift);
  
  /* Update HRTIMx register */
  HRTIMx->HRTIM_TIMERx[TimerIdx].OUTxR = HRTIM_outr;
}

/**
  * @brief  Configures an external event channel 
  * @param  HRTIMx: pointer to HRTIMx peripheral
  * @param  Event: Event channel identifier
  * @param  pEventCfg: pointer to the event channel configuration data structure
  * @retval None
  */
static void HRTIM_ExternalEventConfig(HRTIM_TypeDef * HRTIMx,
                              uint32_t Event,
                              HRTIM_EventCfgTypeDef *pEventCfg)
{
  uint32_t hrtim_eecr1;
  uint32_t hrtim_eecr2;
  uint32_t hrtim_eecr3;

  /* Configure external event channel */
  hrtim_eecr1 = HRTIMx->HRTIM_COMMON.EECR1;
  hrtim_eecr2 = HRTIMx->HRTIM_COMMON.EECR2;
  hrtim_eecr3 = HRTIMx->HRTIM_COMMON.EECR3;
  
  switch (Event)
  {
    case HRTIM_EVENT_1:
    {
      hrtim_eecr1 &= ~(HRTIM_EECR1_EE1SRC | HRTIM_EECR1_EE1POL | HRTIM_EECR1_EE1SNS | HRTIM_EECR1_EE1FAST);
      hrtim_eecr1 |= pEventCfg->Source;
      hrtim_eecr1 |= pEventCfg->Polarity;
      hrtim_eecr1 |= pEventCfg->Sensitivity;
      /* Update the HRTIM registers (all bit fields but EE1FAST bit) */
      HRTIMx->HRTIM_COMMON.EECR1 = hrtim_eecr1;
      /* Update the HRTIM registers (EE1FAST bit) */
      hrtim_eecr1 |= pEventCfg->FastMode;
      HRTIMx->HRTIM_COMMON.EECR1 = hrtim_eecr1;
    }
    break;
    case HRTIM_EVENT_2:
    {
      hrtim_eecr1 &= ~(HRTIM_EECR1_EE2SRC | HRTIM_EECR1_EE2POL | HRTIM_EECR1_EE2SNS | HRTIM_EECR1_EE2FAST);
      hrtim_eecr1 |= (pEventCfg->Source << 6);
      hrtim_eecr1 |= (pEventCfg->Polarity << 6);
      hrtim_eecr1 |= (pEventCfg->Sensitivity << 6);
      /* Update the HRTIM registers (all bit fields but EE2FAST bit) */
      HRTIMx->HRTIM_COMMON.EECR1 = hrtim_eecr1;
      /* Update the HRTIM registers (EE2FAST bit) */
      hrtim_eecr1 |= (pEventCfg->FastMode << 6);
      HRTIMx->HRTIM_COMMON.EECR1 = hrtim_eecr1;
    }
    break;
    case HRTIM_EVENT_3:
    {
      hrtim_eecr1 &= ~(HRTIM_EECR1_EE3SRC | HRTIM_EECR1_EE3POL | HRTIM_EECR1_EE3SNS | HRTIM_EECR1_EE3FAST);
      hrtim_eecr1 |= (pEventCfg->Source << 12);
      hrtim_eecr1 |= (pEventCfg->Polarity << 12);
      hrtim_eecr1 |= (pEventCfg->Sensitivity << 12);
      /* Update the HRTIM registers (all bit fields but EE3FAST bit) */
      HRTIMx->HRTIM_COMMON.EECR1 = hrtim_eecr1;
      /* Update the HRTIM registers (EE3FAST bit) */
      hrtim_eecr1 |= (pEventCfg->FastMode << 12);
      HRTIMx->HRTIM_COMMON.EECR1 = hrtim_eecr1;
    }
    break;
    case HRTIM_EVENT_4:
    {
      hrtim_eecr1 &= ~(HRTIM_EECR1_EE4SRC | HRTIM_EECR1_EE4POL | HRTIM_EECR1_EE4SNS | HRTIM_EECR1_EE4FAST);
      hrtim_eecr1 |= (pEventCfg->Source << 18);
      hrtim_eecr1 |= (pEventCfg->Polarity << 18);
      hrtim_eecr1 |= (pEventCfg->Sensitivity << 18);
      /* Update the HRTIM registers (all bit fields but EE4FAST bit) */
      HRTIMx->HRTIM_COMMON.EECR1 = hrtim_eecr1;
      /* Update the HRTIM registers (EE4FAST bit) */
      hrtim_eecr1 |= (pEventCfg->FastMode << 18);
      HRTIMx->HRTIM_COMMON.EECR1 = hrtim_eecr1;
    }
    break;
    case HRTIM_EVENT_5:
    {
      hrtim_eecr1 &= ~(HRTIM_EECR1_EE5SRC | HRTIM_EECR1_EE5POL | HRTIM_EECR1_EE5SNS | HRTIM_EECR1_EE5FAST);
      hrtim_eecr1 |= (pEventCfg->Source << 24);
      hrtim_eecr1 |= (pEventCfg->Polarity << 24);
      hrtim_eecr1 |= (pEventCfg->Sensitivity << 24);
      /* Update the HRTIM registers (all bit fields but EE5FAST bit) */
      HRTIMx->HRTIM_COMMON.EECR1 = hrtim_eecr1;
      /* Update the HRTIM registers (EE5FAST bit) */
      hrtim_eecr1 |= (pEventCfg->FastMode << 24);
      HRTIMx->HRTIM_COMMON.EECR1 = hrtim_eecr1;
    }
    break;
    case HRTIM_EVENT_6:
    {
      hrtim_eecr2 &= ~(HRTIM_EECR2_EE6SRC | HRTIM_EECR2_EE6POL | HRTIM_EECR2_EE6SNS);
      hrtim_eecr2 |= pEventCfg->Source;
      hrtim_eecr2 |= pEventCfg->Polarity;
      hrtim_eecr2 |= pEventCfg->Sensitivity;
      hrtim_eecr3 &= ~(HRTIM_EECR3_EE6F);
      hrtim_eecr3 |= pEventCfg->Filter;
      /* Update the HRTIM registers */
      HRTIMx->HRTIM_COMMON.EECR2 = hrtim_eecr2;
      HRTIMx->HRTIM_COMMON.EECR3 = hrtim_eecr3;
    }
    break;
    case HRTIM_EVENT_7:
    {
      hrtim_eecr2 &= ~(HRTIM_EECR2_EE7SRC | HRTIM_EECR2_EE7POL | HRTIM_EECR2_EE7SNS);
      hrtim_eecr2 |= (pEventCfg->Source << 6);
      hrtim_eecr2 |= (pEventCfg->Polarity << 6);
      hrtim_eecr2 |= (pEventCfg->Sensitivity << 6);
      hrtim_eecr3 &= ~(HRTIM_EECR3_EE7F);
      hrtim_eecr3 |= (pEventCfg->Filter << 6);
      /* Update the HRTIM registers */
      HRTIMx->HRTIM_COMMON.EECR2 = hrtim_eecr2;
      HRTIMx->HRTIM_COMMON.EECR3 = hrtim_eecr3;
    }
    break;
    case HRTIM_EVENT_8:
    {
      hrtim_eecr2 &= ~(HRTIM_EECR2_EE8SRC | HRTIM_EECR2_EE8POL | HRTIM_EECR2_EE8SNS);
      hrtim_eecr2 |= (pEventCfg->Source << 12);
      hrtim_eecr2 |= (pEventCfg->Polarity << 12);
      hrtim_eecr2 |= (pEventCfg->Sensitivity << 12);
      hrtim_eecr3 &= ~(HRTIM_EECR3_EE8F);
      hrtim_eecr3 |= (pEventCfg->Filter << 12);
      /* Update the HRTIM registers */
      HRTIMx->HRTIM_COMMON.EECR2 = hrtim_eecr2;
      HRTIMx->HRTIM_COMMON.EECR3 = hrtim_eecr3;
    }
    break;
    case HRTIM_EVENT_9:
    {
      hrtim_eecr2 &= ~(HRTIM_EECR2_EE9SRC | HRTIM_EECR2_EE9POL | HRTIM_EECR2_EE9SNS);
      hrtim_eecr2 |= (pEventCfg->Source << 18);
      hrtim_eecr2 |= (pEventCfg->Polarity << 18);
      hrtim_eecr2 |= (pEventCfg->Sensitivity << 18);
      hrtim_eecr3 &= ~(HRTIM_EECR3_EE9F);
      hrtim_eecr3 |= (pEventCfg->Filter << 18);
      /* Update the HRTIM registers */
      HRTIMx->HRTIM_COMMON.EECR2 = hrtim_eecr2;
      HRTIMx->HRTIM_COMMON.EECR3 = hrtim_eecr3;
    }
    break;
    case HRTIM_EVENT_10:
    {
      hrtim_eecr2 &= ~(HRTIM_EECR2_EE10SRC | HRTIM_EECR2_EE10POL | HRTIM_EECR2_EE10SNS);
      hrtim_eecr2 |= (pEventCfg->Source << 24);
      hrtim_eecr2 |= (pEventCfg->Polarity << 24);
      hrtim_eecr2 |= (pEventCfg->Sensitivity << 24);
      hrtim_eecr3 &= ~(HRTIM_EECR3_EE10F);
      hrtim_eecr3 |= (pEventCfg->Filter << 24);
      /* Update the HRTIM registers */
      HRTIMx->HRTIM_COMMON.EECR2 = hrtim_eecr2;
      HRTIMx->HRTIM_COMMON.EECR3 = hrtim_eecr3;
    }
    break;
    default:
    break;
  }
}

/**
  * @brief  Configures the timer counter reset 
  * @param  HRTIMx: pointer to HRTIMx peripheral
  * @param  TimerIdx: Timer index
  * @param  Event: Event channel identifier
  * @retval None
  */
void HRTIM_TIM_ResetConfig(HRTIM_TypeDef * HRTIMx,
                           uint32_t TimerIdx,
                           uint32_t Event)
{
  switch (Event)
  {
    case HRTIM_EVENT_1:
    {
      HRTIMx->HRTIM_TIMERx[TimerIdx].RSTxR = HRTIM_TIMRESETTRIGGER_EEV_1;
    }
    break;
    case HRTIM_EVENT_2:
    {
      HRTIMx->HRTIM_TIMERx[TimerIdx].RSTxR = HRTIM_TIMRESETTRIGGER_EEV_2;
    }
    break;
    case HRTIM_EVENT_3:
    {
      HRTIMx->HRTIM_TIMERx[TimerIdx].RSTxR = HRTIM_TIMRESETTRIGGER_EEV_3;
    }
    break;
    case HRTIM_EVENT_4:
    {
      HRTIMx->HRTIM_TIMERx[TimerIdx].RSTxR = HRTIM_TIMRESETTRIGGER_EEV_4;
    }
    break;
    case HRTIM_EVENT_5:
    {
      HRTIMx->HRTIM_TIMERx[TimerIdx].RSTxR = HRTIM_TIMRESETTRIGGER_EEV_5;
    }
    break;
    case HRTIM_EVENT_6:
    {
      HRTIMx->HRTIM_TIMERx[TimerIdx].RSTxR = HRTIM_TIMRESETTRIGGER_EEV_6;
    }
    break;
    case HRTIM_EVENT_7:
    {
      HRTIMx->HRTIM_TIMERx[TimerIdx].RSTxR = HRTIM_TIMRESETTRIGGER_EEV_7;
    }
    break;
    case HRTIM_EVENT_8:
    {
      HRTIMx->HRTIM_TIMERx[TimerIdx].RSTxR = HRTIM_TIMRESETTRIGGER_EEV_8;
    }
    break;
    case HRTIM_EVENT_9:
    {
      HRTIMx->HRTIM_TIMERx[TimerIdx].RSTxR = HRTIM_TIMRESETTRIGGER_EEV_9;
    }
    break;
    case HRTIM_EVENT_10:
    {
      HRTIMx->HRTIM_TIMERx[TimerIdx].RSTxR = HRTIM_TIMRESETTRIGGER_EEV_10;
    }
    break;
    default:
    break;
  }
}
/**
  * @}
  */
/**
  * @}
  */

/**
  * @}
  */

/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/