summaryrefslogtreecommitdiffstats
path: root/bsps/arm/altera-cyclone-v/include/bsp/alt_clock_manager.h
blob: d6d96544f74f48d95464dab43bbbcce54c71cde7 (plain) (blame)
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
/*! \file
 *  Contains definitions for the Altera Hardware Libraries Clock Manager
 *  Application Programming Interface
 */

/******************************************************************************
*
* Copyright 2013 Altera Corporation. All Rights Reserved.
*
* 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. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER "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 AUTHOR 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.
*
******************************************************************************/

#ifndef __ALT_CLK_MGR_H__
#define __ALT_CLK_MGR_H__

#include "hwlib.h"
#include "alt_clock_group.h"

#ifdef __cplusplus
extern "C"
{
#endif  /* __cplusplus */

/*! \addtogroup CLK_MGR The Clock Manager API
 *
 * This module defines the Clock Manager API for accessing, configuring, and
 * controlling the HPS clock resources.
 *
 * @{
 */

/******************************************************************************/
/*!
 * This type definition is an opaque type definition for clock frequency values
 * in Hz.
 */
typedef uint32_t    alt_freq_t;

/******************************************************************************/
/*!
 * This type definition enumerates the names of the clock and PLL resources
 * managed by the Clock Manager.
 */
typedef enum ALT_CLK_e
{
    /* Clock Input Pins */
    ALT_CLK_IN_PIN_OSC1,
                                        /*!< \b OSC_CLK_1_HPS
                                         *   External oscillator input:
                                         *   * Input Pin
                                         *   * Clock source to Main PLL
                                         *   * Clock source to SDRAM PLL
                                         *     and Peripheral PLL if selected via
                                         *     register write
                                         *   * Clock source for clock in safe mode
                                         */

    ALT_CLK_IN_PIN_OSC2,
                                        /*!< \b OSC_CLK_2_HPS
                                         *   External Oscillator input:
                                         *   * Input Pin
                                         *   * Optional clock source to SDRAM PLL
                                         *     and Peripheral PLL if selected
                                         *   * Typically used for Ethernet
                                         *     reference clock
                                         */


    /* FPGA Clock Sources External to HPS */
    ALT_CLK_F2H_PERIPH_REF,
                                        /*<! Alternate clock source from FPGA
                                         * for HPS Peripheral PLL. */

    ALT_CLK_F2H_SDRAM_REF,
                                        /*<! Alternate clock source from FPGA
                                         * for HPS SDRAM PLL. */


    /* Other Clock Sources External to HPS */
    ALT_CLK_IN_PIN_JTAG,
                                        /*!< \b JTAG_TCK_HPS
                                         *   * Input Pin
                                         *   * External HPS JTAG clock input.
                                         */

    ALT_CLK_IN_PIN_ULPI0,
                                        /*!< \b ULPI0_CLK
                                         *   ULPI Clock provided by external USB0
                                         *   PHY
                                         *   * Input Pin
                                         */

    ALT_CLK_IN_PIN_ULPI1,
                                        /*!< \b ULPI1_CLK
                                         *   ULPI Clock provided by external USB1
                                         *   PHY
                                         *   * Input Pin
                                         */

    ALT_CLK_IN_PIN_EMAC0_RX,
                                        /*!< \b EMAC0:RX_CLK
                                         *   Rx Reference Clock for EMAC0
                                         *   * Input Pin
                                         */

    ALT_CLK_IN_PIN_EMAC1_RX,
                                        /*!< \b EMAC1:RX_CLK
                                         *   Rx Reference Clock for EMAC1
                                         *   * Input Pin
                                         */


    /* PLLs */
    ALT_CLK_MAIN_PLL,
                                        /*!< \b main_pll_ref_clkin
                                         *   Main PLL input reference clock,
                                         *   used to designate the Main PLL in
                                         *   PLL clock selections.
                                         */

    ALT_CLK_PERIPHERAL_PLL,
                                        /*!< \b periph_pll_ref_clkin
                                         *   Peripheral PLL input reference
                                         *   clock, used to designate the
                                         *   Peripheral PLL in PLL clock
                                         *   selections.
                                         */

    ALT_CLK_SDRAM_PLL,
                                        /*!< \b sdram_pll_ref_clkin
                                         *   SDRAM PLL input reference clock,
                                         *   used to designate the SDRAM PLL in
                                         *   PLL clock selections.
                                         */

    /* OSC1 Clock Group - The OSC1 clock group contains those clocks which are derived
     * directly from the osc_clk_1_HPS pin */
    ALT_CLK_OSC1,
                                        /*!< \b osc1_clk
                                         *   OSC1 Clock Group - The
                                         *   OSC1 clock group contains
                                         *   those clocks which are
                                         *   derived directly from the
                                         *   osc_clk_1_HPS pin.
                                         *   * alias for ALT_CLK_IN_PIN_OSC1
                                         */

    /* Main Clock Group - The following clocks are derived from the Main PLL. */
    ALT_CLK_MAIN_PLL_C0,
                                        /*!< \b Main PLL C0 Output */

    ALT_CLK_MAIN_PLL_C1,
                                        /*!< \b Main PLL C1 Output */

    ALT_CLK_MAIN_PLL_C2,
                                        /*!< \b Main PLL C2 Output */

    ALT_CLK_MAIN_PLL_C3,
                                        /*!< \b Main PLL C3 Output */

    ALT_CLK_MAIN_PLL_C4,
                                        /*!< \b Main PLL C4 Output */

    ALT_CLK_MAIN_PLL_C5,
                                        /*!< \b Main PLL C5 Output */

    ALT_CLK_MPU,
                                        /*!< \b mpu_clk
                                         *   Main PLL C0 Output. Clock for MPU
                                         *   subsystem, including CPU0 and CPU1.
                                         *   * Alias for \e ALT_CLK_MAIN_PLL_C0
                                         */

    ALT_CLK_MPU_L2_RAM,
                                        /*!< \b mpu_l2_ram_clk
                                         *   Clock for MPU level 2 (L2) RAM
                                         */

    ALT_CLK_MPU_PERIPH,
                                        /*!< \b mpu_periph_clk
                                         *   Clock for MPU snoop control unit
                                         *   (SCU) peripherals, such as the
                                         *   general interrupt controller (GIC)
                                         */

    ALT_CLK_L3_MAIN,
                                        /*!< \b main_clk
                                         *   Main PLL C1 Output
                                         *   * Alias for \e ALT_CLK_MAIN_PLL_C1
                                         */

    ALT_CLK_L3_MP,
                                        /*!< \b l3_mp_clk
                                         *   Clock for L3 Master Peripheral Switch
                                         */

    ALT_CLK_L3_SP,
                                        /*!< \b l3_sp_clk
                                         *   Clock for L3 Slave Peripheral Switch
                                         */

    ALT_CLK_L4_MAIN,
                                        /*!< \b l4_main_clk
                                         *   Clock for L4 main bus
                                         *   * Clock for DMA
                                         *   * Clock for SPI masters
                                         */

    ALT_CLK_L4_MP,
                                        /*!< \b l4_mp_clk
                                         *   Clock for L4 master peripherals (MP) bus
                                         */

    ALT_CLK_L4_SP,
                                        /*!< \b l4_sp_clk
                                         *   Clock for L4 slave peripherals (SP) bus
                                         */

    ALT_CLK_DBG_BASE,
                                        /*!< \b dbg_base_clk
                                         *   Main PLL C2 Output
                                         *   * Alias for \e ALT_CLK_MAIN_PLL_C2
                                         */

    ALT_CLK_DBG_AT,
                                        /*!< \b dbg_at_clk
                                         *   Clock for CoreSight debug Advanced
                                         *   Microcontroller Bus Architecture
                                         *   (AMBA) Trace Bus (ATB)
                                         */

    ALT_CLK_DBG_TRACE,
                                        /*!< \b dbg_trace_clk
                                         *   Clock for CoreSight debug Trace
                                         *   Port Interface Unit (TPIU)
                                         */

    ALT_CLK_DBG_TIMER,
                                        /*!< \b dbg_timer_clk
                                         *   Clock for the trace timestamp
                                         *   generator
                                         */

    ALT_CLK_DBG,
                                        /*!< \b dbg_clk
                                         *   Clock for Debug Access Port (DAP)
                                         *   and debug Advanced Peripheral Bus
                                         *   (APB)
                                         */

    ALT_CLK_MAIN_QSPI,
                                        /*!< \b main_qspi_clk
                                         *   Main PLL C3 Output. Quad SPI flash
                                         *   internal logic clock.
                                         *   * Alias for \e ALT_CLK_MAIN_PLL_C3
                                         */

    ALT_CLK_MAIN_NAND_SDMMC,
                                        /*!< \b main_nand_sdmmc_clk
                                         *   Main PLL C4 Output. Input clock to
                                         *   flash controller clocks block.
                                         *   * Alias for \e ALT_CLK_MAIN_PLL_C4
                                         */

    ALT_CLK_CFG,
                                        /*!< \b cfg_clk
                                         *   FPGA manager configuration clock.
                                         */

    ALT_CLK_H2F_USER0,
                                        /*!< \b h2f_user0_clock
                                         *   Clock to FPGA fabric
                                         */


    /* Peripherals Clock Group - The following clocks are derived from the Peripheral PLL */
    ALT_CLK_PERIPHERAL_PLL_C0,
                                        /*!< \b Peripheral PLL C0 Output */

    ALT_CLK_PERIPHERAL_PLL_C1,
                                        /*!< \b Peripheral PLL C1 Output */

    ALT_CLK_PERIPHERAL_PLL_C2,
                                        /*!< \b Peripheral PLL C2 Output */

    ALT_CLK_PERIPHERAL_PLL_C3,
                                        /*!< \b Peripheral PLL C3 Output */

    ALT_CLK_PERIPHERAL_PLL_C4,
                                        /*!< \b Peripheral PLL C4 Output */

    ALT_CLK_PERIPHERAL_PLL_C5,
                                        /*!< \b Peripheral PLL C5 Output */

    ALT_CLK_USB_MP,
                                        /*!< \b usb_mp_clk
                                         *   Clock for USB
                                         */

    ALT_CLK_SPI_M,
                                        /*!< \b spi_m_clk
                                         *   Clock for L4 SPI master bus
                                         */

    ALT_CLK_QSPI,
                                        /*!< \b qspi_clk
                                         *   Clock for Quad SPI
                                         */

    ALT_CLK_NAND_X,
                                        /*!< \b nand_x_clk
                                         *   NAND flash controller master and
                                         *   slave clock
                                         */

    ALT_CLK_NAND,
                                        /*!< \b nand_clk
                                         *   Main clock for NAND flash
                                         *   controller
                                         */

    ALT_CLK_SDMMC,
                                        /*!< \b sdmmc_clk
                                         *   Clock for SD/MMC logic input clock
                                         */

    ALT_CLK_EMAC0,
                                        /*!< \b emac0_clk
                                         *   EMAC 0 clock - Peripheral PLL C0
                                         *   Output
                                         *   * Alias for \e ALT_CLK_PERIPHERAL_PLL_C0
                                         */

    ALT_CLK_EMAC1,
                                        /*!< \b emac1_clk
                                         *   EMAC 1 clock - Peripheral PLL C1
                                         *   Output
                                         *   * Alias for \e ALT_CLK_PERIPHERAL_PLL_C1
                                         */

    ALT_CLK_CAN0,
                                        /*!< \b can0_clk
                                         *   Controller area network (CAN)
                                         *   controller 0 clock
                                         */

    ALT_CLK_CAN1,
                                        /*!< \b can1_clk
                                         *   Controller area network (CAN)
                                         *   controller 1 clock
                                         */

    ALT_CLK_GPIO_DB,
                                        /*!< \b gpio_db_clk
                                         *   Debounce clock for GPIO0, GPIO1,
                                         *   and GPIO2
                                         */

    ALT_CLK_H2F_USER1,
                                        /*!< \b h2f_user1_clock
                                         *   Clock to FPGA fabric - Peripheral
                                         *   PLL C5 Output
                                         *   * Alias for \e ALT_CLK_PERIPHERAL_PLL_C5
                                         */


    /* SDRAM Clock Group - The following clocks are derived from the SDRAM PLL */
    ALT_CLK_SDRAM_PLL_C0,
                                        /*!< \b SDRAM PLL C0 Output */

    ALT_CLK_SDRAM_PLL_C1,
                                        /*!< \b SDRAM PLL C1 Output */

    ALT_CLK_SDRAM_PLL_C2,
                                        /*!< \b SDRAM PLL C2 Output */

    ALT_CLK_SDRAM_PLL_C3,
                                        /*!< \b SDRAM PLL C3 Output */

    ALT_CLK_SDRAM_PLL_C4,
                                        /*!< \b SDRAM PLL C4 Output */

    ALT_CLK_SDRAM_PLL_C5,
                                        /*!< \b SDRAM PLL C5 Output */

    ALT_CLK_DDR_DQS,
                                        /*!< \b ddr_dqs_clk
                                         *   Clock for MPFE, single-port
                                         *   controller, CSR access, and PHY -
                                         *   SDRAM PLL C0 Output
                                         *   * Alias for \e ALT_CLK_SDRAM_PLL_C0
                                         */

    ALT_CLK_DDR_2X_DQS,
                                        /*!< \b ddr_2x_dqs_clk
                                         *    Clock for PHY - SDRAM PLL C1 Output
                                         *   * Alias for \e ALT_CLK_SDRAM_PLL_C1
                                         */

    ALT_CLK_DDR_DQ,
                                        /*!< \b ddr_dq_clk
                                         *   Clock for PHY - SDRAM PLL C2 Output
                                         *   * Alias for \e ALT_CLK_SDRAM_PLL_C2
                                         */

    ALT_CLK_H2F_USER2,
                                        /*!< \b h2f_user2_clock
                                         *   Clock to FPGA fabric - SDRAM PLL C5
                                         *   Output
                                         *   * Alias for \e ALT_CLK_SDRAM_PLL_C5
                                         */

    /* Clock Output Pins */
    ALT_CLK_OUT_PIN_EMAC0_TX,
                                       /*!< \b EMAC0:TX_CLK
                                        *   Tx Reference Clock for EMAC0
                                        *   * Output Pin
                                        */

    ALT_CLK_OUT_PIN_EMAC1_TX,
                                       /*!< \b EMAC1:TX_CLK
                                        *   Tx Reference Clock for EMAC1
                                        *   * Output Pin
                                        */

    ALT_CLK_OUT_PIN_SDMMC,
                                       /*!< \b SDMMC:CLK
                                        *   SD/MMC Card Clock
                                        *   * Output Pin
                                        */

    ALT_CLK_OUT_PIN_I2C0_SCL,
                                       /*!< \b I2C0:SCL
                                        *   I2C Clock for I2C0
                                        *   * Output Pin
                                        */

    ALT_CLK_OUT_PIN_I2C1_SCL,
                                       /*!< \b I2C1:SCL
                                        *   I2C Clock for I2C1
                                        *   * Output Pin
                                        */

    ALT_CLK_OUT_PIN_I2C2_SCL,
                                       /*!< \b I2C2:SCL
                                        *   I2C Clock for I2C2/2 wire
                                        *   * Output Pin
                                        */

    ALT_CLK_OUT_PIN_I2C3_SCL,
                                       /*!< \b I2C3:SCL
                                        *   I2C Clock for I2C1/2 wire
                                        *   * Output Pin
                                        */

    ALT_CLK_OUT_PIN_SPIM0,
                                       /*!< \b SPIM0:CLK
                                        *   SPI Clock
                                        *   * Output Pin
                                        */

    ALT_CLK_OUT_PIN_SPIM1,
                                       /*!< \b SPIM1:CLK
                                        *   SPI Clock
                                        *   * Output Pin
                                        */

    ALT_CLK_OUT_PIN_QSPI,
                                       /*!< \b QSPI:CLK
                                        *   QSPI Flash Clock
                                        *   * Output Pin
                                        */

    ALT_CLK_UNKNOWN
} ALT_CLK_t;

/******************************************************************************/
/*! \addtogroup CLK_MGR_STATUS Clock Manager Status
 *
 * This functional group provides status information on various aspects and
 * properties of the Clock Manager state.
 *
 * @{
 */
/******************************************************************************/
/*!
 * This type definition defines the lock condition status codes for each of the
 * PLLs. If the PLL lock status condition is enabled (See: alt_clk_irq_enable())
 * then it contributes to the overall \b clkmgr_IRQ signal assertion state.
 */
typedef enum ALT_CLK_PLL_LOCK_STATUS_e
{
    ALT_MAIN_PLL_LOCK_ACHV    = 0x00000001, /*!< This condition is set if the Main
                                             *   PLL has achieved lock at least once
                                             *   since this condition was last
                                             *   cleared.
                                             */
    ALT_PERIPH_PLL_LOCK_ACHV  = 0x00000002, /*!< This condition is set if the Peripheral
                                             *   PLL has achieved lock at least once
                                             *   since this condition was last
                                             *   cleared.
                                             */
    ALT_SDR_PLL_LOCK_ACHV     = 0x00000004, /*!< This condition is set if the SDRAM
                                             *   PLL has achieved lock at least once
                                             *   since this condition was last
                                             *   cleared.
                                             */
    ALT_MAIN_PLL_LOCK_LOST    = 0x00000008, /*!< This condition is set if the Main
                                             *   PLL has lost lock at least once
                                             *   since this condition was last
                                             *   cleared.
                                             */
    ALT_PERIPH_PLL_LOCK_LOST  = 0x00000010, /*!< This condition is set if the Peripheral
                                             *   PLL has lost lock at least once
                                             *   since this condition was last
                                             *   cleared.
                                             */
    ALT_SDR_PLL_LOCK_LOST     = 0x00000020  /*!< This condition is set if the SDRAM
                                             *   PLL has lost lock at least once
                                             *   since this condition was last
                                             *   cleared.
                                             */
} ALT_CLK_PLL_LOCK_STATUS_t;

/******************************************************************************/
/*!
 * Clear the selected PLL lock status conditions.
 *
 * This function clears assertions of one or more of the PLL lock status
 * conditions.
 *
 * NOTE: This function is used to clear \b clkmgr_IRQ interrupt signal source
 * assertion conditions.
 *
 * \param       lock_stat_mask
 *              Specifies the PLL lock status conditions to clear. \e lock_stat_mask
 *              is a mask of logically OR'ed \ref ALT_CLK_PLL_LOCK_STATUS_t
 *              values designating the PLL lock conditions to clear.
 *
 * \retval      ALT_E_SUCCESS   Successful status.
 * \retval      ALT_E_BAD_ARG   The \e lock_stat_mask argument contains an
 *                              unknown condition value.
 */
ALT_STATUS_CODE alt_clk_lock_status_clear(ALT_CLK_PLL_LOCK_STATUS_t lock_stat_mask);

/******************************************************************************/
/*!
 * Returns the PLL lock status condition values.
 *
 * This function returns the value of the PLL lock status conditions.
 *
 * \returns The current values of the PLL lock status conditions as defined by
 * the \ref ALT_CLK_PLL_LOCK_STATUS_t mask bits. If the corresponding bit is set
 * then the condition is asserted.
 */
uint32_t alt_clk_lock_status_get(void);

/******************************************************************************/
/*!
 * Returns ALT_E_TRUE if the designated PLL is currently locked and ALT_E_FALSE
 * otherwise.
 *
 * \param       pll
 *              The PLL to return the lock status of.
 *
 * \retval      ALT_E_TRUE      The specified PLL is currently locked.
 * \retval      ALT_E_FALSE     The specified PLL is currently not locked.
 * \retval      ALT_E_BAD_ARG   The \e pll argument designates a non PLL clock
 *                              value.
 * \internal
 * NOTE: This function uses the
 *       * \b hps::clkmgr::inter::mainplllocked
 *       * \b hps::clkmgr::inter::perplllocked,
 *       * \b hps::clkmgr::inter::sdrplllocked
 *
 *       bits to determine if the PLL is locked or not.
 * \endinternal
 */
ALT_STATUS_CODE alt_clk_pll_is_locked(ALT_CLK_t pll);

/*! @} */

/******************************************************************************/
/*! \addtogroup CLK_MGR_SAFE_MODE Safe Mode Options
 *
 * When safe mode is enabled, clocks in the HPS are directly generated from the
 * \b osc1_clk clock. Safe mode is enabled by the assertion of a safe mode
 * request from the reset manager or by a cold reset. Assertion of the safe mode
 * request from the reset manager sets the safe mode bit in the clock manager
 * control register. No other control register bits are affected by the safe
 * mode request from the reset manager.
 *
 * While in safe mode, clock manager register settings which control clock
 * behavior are not changed. However, the output of the registers which control
 * the clock manager state are forced to the safe mode values such that the
 * following conditions occur:
 * * All PLLs are bypassed to the \b osc1_clk clock, including their counters.
 * * Clock dividers select their default reset values.
 * * The flash controllers source clock selections are set to the peripheral
 *   PLL.
 * * All clocks are enabled.
 * * Safe mode is optionally applied to debug clocks.
 *
 * A write by software is the only way to clear the safe mode bit. All registers
 * and clocks need to be configured correctly and all software-managed clocks
 * need to be gated off before clearing safe mode. Software can then gate clocks
 * on as required.
 *
 * On cold reset, all clocks are put in safe mode.
 *
 * On warm reset, safe mode is optionally and independently applied to debug
 * clocks and normal (i.e.non-debug) clocks based on clock manager register
 * settings. The default response for warm reset is to put all clocks in safe
 * mode.
 *
 * The APIs in this group provide control of the Clock Manager safe mode warm
 * reset response behavior.
 * @{
 */

/******************************************************************************/
/*!
 * This type definition enumerates the safe mode clock domains under control of
 * the Clock Manager.
 */
typedef enum ALT_CLK_SAFE_DOMAIN_e
{
    /*!
     * This enumeration literal specifies the normal safe mode domain. The
     * normal domain consists of all clocks except debug clocks.
     */
    ALT_CLK_DOMAIN_NORMAL,
    /*!
     * This enumeration literal specifies the debug safe mode domain. The debug
     * domain consists of all debug clocks.
     */
    ALT_CLK_DOMAIN_DEBUG
} ALT_CLK_SAFE_DOMAIN_t;

/******************************************************************************/
/*!
 * Clear the safe mode status of the Clock Manager following a reset.
 *
 * NOTE: Safe mode should only be cleared once clocks have been correctly
 * configured.
 *
 * \retval      ALT_E_SUCCESS   The operation was succesful.
 * \retval      ALT_E_ERROR     The operation failed.
 */
ALT_STATUS_CODE alt_clk_safe_mode_clear(void);

/******************************************************************************/
/*!
 * Return whether the specified safe mode clock domain is in safe mode or not.
 *
 * \param       clk_domain
 *              The safe mode clock domain to check whether in safe mode or not.
 *
 * \retval      TRUE            The safe mode clock domain is in safe mode.
 * \retval      FALSE           The safe mode clock domain is not in safe mode.
 */
bool alt_clk_is_in_safe_mode(ALT_CLK_SAFE_DOMAIN_t clk_domain);

/*! @} */

/******************************************************************************/
/*! \addtogroup CLK_MGR_BYPASS PLL Bypass Control
 *
 * When a PLL is in bypass, the PLL clock logic is kept in reset. In this
 * manner, the PLL clock can be free running while it stabilizes and achieves
 * lock. The bypass logic isolates PLL configuration registers from the clock
 * while changes are made to the PLL settings.
 *
 * The bypass controls are used by software to change the source clock input
 * reference (for Peripheral and SDRAM PLLs) and is recommended when changing
 * settings that may affect the ability of the VCO to maintain lock.  When a PLL
 * is taken in or out of bypass the PLL output clocks will pause momentarily
 * while the clocks are in transition, There will be no glitches or clocks
 * shorter than the either the old or the new clock period.
 *
 * In summary, the PLL bypass controls permit:
 * * Each PLL to be individually bypassed.
 * * Bypass of all PLL clock outputs to \b osc1_clk or alternatively the PLLs
 *   reference clock input source reference clock selection.
 * * Isolation of a the PLL VCO frequency registers (multiplier and divider),
     phase shift registers (negative phase) , and post scale counters.
 * * Glitch free clock transitions.
 * @{
 */
/******************************************************************************/
/*!
 * Disable bypass mode for the specified PLL. This operation takes the PLL out
 * of bypass mode.
 *
 * \param       pll
 *              The PLL to take out of bypass mode.
 *
 * \retval      ALT_E_SUCCESS   The operation was succesful.
 * \retval      ALT_E_ERROR     The operation failed.
 * \retval      ALT_E_BAD_ARG   The \e pll argument specified a non PLL clock
 *                              value.
 */
ALT_STATUS_CODE alt_clk_pll_bypass_disable(ALT_CLK_t pll);

/******************************************************************************/
/*!
 * Enable bypass mode for the specified PLL.
 *
 * \param       pll
 *              The PLL to put into bypass mode.
 *
 * \param       use_input_mux
 *              If TRUE then use the PLLs reference clock input source selection
 *              to directly drive the bypass clock. If FALSE then use bypass
 *              clock directly driven by the \b osc1_clk.
 *
 * \retval      ALT_E_SUCCESS       The operation was succesful.
 * \retval      ALT_E_ERROR         The operation failed.
 * \retval      ALT_E_BAD_ARG       The \e pll argument specified a non PLL
 *                                  clock value.
 * \retval      ALT_E_INV_OPTION    TRUE is an invalid option for
 *                                  \e use_input_mux with the \e pll selection.
 */
ALT_STATUS_CODE alt_clk_pll_bypass_enable(ALT_CLK_t pll,
                                          bool use_input_mux);

/******************************************************************************/
/*!
 * Return whether the specified PLL is in bypass or not.
 *
 * \internal
 * This function must also test the \b clkmgr.ctrl.safemode bit in
 * addition to the PLLs bypass bit to tell whether the bypass mode is
 * effect or not.
 * \endinternal
 *
 * \param       pll
 *              The PLL to check whether in bypass mode or not.
 *
 * \retval      ALT_E_TRUE      The PLL is in bypass mode.
 * \retval      ALT_E_FALSE     The PLL is not in bypass mode.
 * \retval      ALT_E_BAD_ARG   The \e pll argument designates a non PLL clock
 *                              value.
 */
ALT_STATUS_CODE alt_clk_pll_is_bypassed(ALT_CLK_t pll);

/*! @} */

/******************************************************************************/
/*! \addtogroup CLK_MGR_GATE Clock Gating Control
 *
 * This functional group provides gating control of selected clock signals.
 *
 * When a clock is enabled, then its clock signal propogates to its respective
 * clocked IP block(s).  When a clock is disabled, then its clock signal is
 * prevented from propogating to its respective clocked IP block(s).
 *
 * The following clocks may be gated:
 *
 * * Main PLL Group
 *   - l4_main_clk
 *   - l3_mp_clk
 *   - l4_mp_clk
 *   - l4_sp_clk
 *   - dbg_at_clk
 *   - dbg_clk
 *   - dbg_trace_clk
 *   - dbg_timer_clk
 *   - cfg_clk
 *   - s2f_user0_clk
 *
 * * SDRAM PLL Group
 *   - ddr_dqs_clk
 *   - ddr_2x_clk
 *   - ddr_dq_clk
 *   - s2f_user2_clk
 *
 * * Peripheral PLL Group
 *   - emac0_clk
 *   - emac1_clk
 *   - usb_mp_clk
 *   - spi_m_clk
 *   - can0_clk
 *   - can1_clk
 *   - gpio_db_clk
 *   - s2f_user1_clk
 *   - sdmmc_clk
 *   - nand_clk
 *   - nand_x_clk
 *   - qspi_clk
 *
 * @{
 */
/******************************************************************************/
/*!
 * Disable the specified clock. Once the clock is disabled, its clock signal does
 * not propogate to its clocked elements.
 *
 * \param       clk
 *              The clock to disable.
 *
 * \retval      ALT_E_SUCCESS   The operation was succesful.
 * \retval      ALT_E_ERROR     The operation failed.
 * \retval      ALT_E_BAD_ARG   The \e clk argument designates a non gated clock
 *                              value.
 */
ALT_STATUS_CODE alt_clk_clock_disable(ALT_CLK_t clk);

/******************************************************************************/
/*!
 * Enable the specified clock. Once the clock is enabled, its clock signal
 * propogates to its elements.
 *
 * \param       clk
 *              The clock to enable.
 *
 * \retval      ALT_E_SUCCESS   The operation was succesful.
 * \retval      ALT_E_ERROR     The operation failed.
 * \retval      ALT_E_BAD_ARG   The \e clk argument designates a non gated clock
 *                              value.
 */
ALT_STATUS_CODE alt_clk_clock_enable(ALT_CLK_t clk);

/******************************************************************************/
/*!
 * Return whether the specified clock is enabled or not.
 *
 * \param       clk
 *              The clock to check whether enabled or not.
 *
 * \retval      ALT_E_TRUE      The clock is enabled.
 * \retval      ALT_E_FALSE     The clock is not enabled.
 * \retval      ALT_E_BAD_ARG   The \e clk argument designates a non gated clock
 *                              value.
 */
ALT_STATUS_CODE alt_clk_is_enabled(ALT_CLK_t clk);

/*! @} */

/******************************************************************************/
/*! \addtogroup CLK_MGR_CLK_SEL Clock Source Selection
 *
 * This API group provide access and control to the input reference clock source
 * selection for a clock or PLL.
 *
 * \internal
 * These are the clocks that have software configurable input reference clock
 * source selection available. Each clock below is listed with its valid
 * input reference clock source selections.
 *
 * + Valid reference clock input selections for \b sdram_pll_ref_clkin
 *   - osc_clk_1
 *   - osc_clk_2
 *   - f2h_sdram_ref_clk
 *
 * + Valid reference clock input selections for \b periph_pll_ref_clkin
 *   - osc_clk_1
 *   - osc_clk_2,
 *   - f2h_periph_ref_clk
 *
 * + Valid reference clock input selections for \b l4_mp_clk
 *   - periph_base_clk
 *   - main_clk
 *
 * + Valid reference clock input selections for \b l4_sp_clk
 *   - periph_base_clk
 *   - main_clk
 *
 * + Valid reference clock input selections for \b sdmmc_clk
 *   - f2h_periph_ref_clk
 *   - main_nand_sdmmc_clk
 *   - periph_nand_sdmmc_clk
 *
 * + Valid reference clock input selections for \b nand_clk
 *   - f2h_periph_ref_clk
 *   - main_nand_sdmmc_clk
 *   - periph_nand_sdmmc_clk
 *
 * + Valid reference clock input selections for \b qspi_clk
 *   - f2h_periph_ref_clk
 *   - main_qspi_clk
 *   - periph_qspi_clk
 *
 * \endinternal
 * @{
 */
/******************************************************************************/
/*!
 * Get the input reference clock source selection value for the specified clock
 * or PLL.
 *
 * NOTE: This function returns a clock value even though \e clk may specify a
 *       clock that does not have a selectable input reference clock source. In
 *       this case, the clock value returned is the static clock source for the
 *       specified clock. For example calling alt_clk_source_get() with \e clk
 *       set to \ref ALT_CLK_MAIN_PLL will return \ref ALT_CLK_OSC1.
 *
 * \param       clk
 *              The clock or PLL to retrieve the input reference clock source
 *              selection value for.
 *
 * \returns     The clock's currently selected input reference clock source.
 */
ALT_CLK_t alt_clk_source_get(ALT_CLK_t clk);

/******************************************************************************/
/*!
 * Set the specified clock's input reference clock source selection.
 *
 * \param       clk
 *              The clock or PLL to set the input reference clock source
 *              selection for.
 *
 * \param       ref_clk
 *              The input reference clock source selection value.
 *
 * \retval      ALT_E_SUCCESS       The operation was succesful.
 * \retval      ALT_E_ERROR         The operation failed.
 * \retval      ALT_E_BAD_ARG       The \e clk argument designates a clock that
 *                                  does not have a selectable input reference
 *                                  clock source.
 * \retval      ALT_E_INV_OPTION    The \e ref_clk argument designates a clock that
 *                                  is an invalid reference clock source for the
 *                                  specified clock.
 */
ALT_STATUS_CODE alt_clk_source_set(ALT_CLK_t clk,
                                   ALT_CLK_t ref_clk);

/*! @} */

/******************************************************************************/
/*! \addtogroup CLK_MGR_FREQ Clock Frequency Control
 *
 * This API group provides access and control of the output frequency of a clock
 * or PLL.
 *
 * @{
 */

/******************************************************************************/
/*!
 * Set the external clock frequency value.
 *
 * The function is used to specify the frequency of the external clock source as
 * a measure of Hz. The supplied frequency should be within the Fmin and Fmax
 * values allowed for the external clock source.
 *
 * \param       clk
 *              The external clock source. Valid external clocks are
 *              * \e ALT_CLK_OSC1
 *              * \e ALT_CLK_OSC2
 *              * \e ALT_CLK_F2H_PERIPH_REF
 *              * \e ALT_CLK_F2H_SDRAM_REF
 *
 * \param       freq
 *              The frequency of the external clock in Hz.
 *
 * \retval      ALT_E_SUCCESS   The operation was succesful.
 * \retval      ALT_E_ERROR     The operation failed.
 * \retval      ALT_E_BAD_ARG   A bad argument value was passed. Either the \e clk
 *                              argument is bad or not a valid external clock
 *                              source
 * \retval      ALT_E_ARG_RANGE The frequency value violates the range constraints
 *                              for the specified clock.

 */
ALT_STATUS_CODE alt_clk_ext_clk_freq_set(ALT_CLK_t clk,
                                         alt_freq_t freq);

/******************************************************************************/
/*!
 * Get the external clock frequency value.
 *
 * This function returns the frequency of the external clock source as
 * a measure of Hz.
 *
 * \param       clk
 *              The external clock source. Valid external clocks are
 *              * \e ALT_CLK_OSC1
 *              * \e ALT_CLK_OSC2
 *              * \e ALT_CLK_F2H_PERIPH_REF
 *              * \e ALT_CLK_F2H_SDRAM_REF
 *
 * \retval      freq
 *              The frequency of the external clock in Hz.
 *
 */
alt_freq_t alt_clk_ext_clk_freq_get(ALT_CLK_t clk);

/******************************************************************************/
/*!
 * This type definition defines a structure to contain the generalized
 * configuration settings for a PLL.
 */
typedef struct ALT_CLK_PLL_CFG_s
{
    ALT_CLK_t           ref_clk;        /*!< PLL Reference Clock Source */
    uint32_t            mult;           /*!< VCO Frequency Configuration -
                                         *   Multiplier (M) value, range 1 to 4096
                                         */
    uint32_t            div;            /*!< VCO Frequency Configuration -
                                         *   Divider (N) value, range 1 to 64
                                         */
    uint32_t            cntrs[6];       /*!< Post-Scale Counters (C0 - C5) -
                                         *   range 1 to 512
                                         */
    uint32_t            pshift[6];      /*!< Phase Shift - 1/8 (45 degrees) of
                                         *   negative phase shift per increment,
                                         *   range 0 to 4096
                                         */
} ALT_CLK_PLL_CFG_t;

/******************************************************************************/
/*!
 * Get the current PLL configuration.
 *
 * \param       pll
 *              The PLL to get the configuration from.
 *
 * \param       pll_cfg
 *              [out] Pointer to an output parameter variable for the returned
 *              PLL configuration.
 *
 * \retval      ALT_E_SUCCESS   The operation was succesful.
 * \retval      ALT_E_ERROR     The operation failed.
 */
ALT_STATUS_CODE alt_clk_pll_cfg_get(ALT_CLK_t pll,
                                    ALT_CLK_PLL_CFG_t* pll_cfg);

/******************************************************************************/
/*!
 * Set the PLL configuration using the configuration parameters specified in
 * \e pll_cfg.
 *
 * \param       pll
 *              The PLL to set the configuration for.
 *
 * \param       pll_cfg
 *              Pointer to a ALT_CLK_PLL_CFG_t structure specifying the desired
 *              PLL configuration.
 *
 * \retval      ALT_E_SUCCESS   The operation was succesful.
 * \retval      ALT_E_ERROR     The operation failed.
 */
ALT_STATUS_CODE alt_clk_pll_cfg_set(ALT_CLK_t pll,
                                    const ALT_CLK_PLL_CFG_t* pll_cfg);

/******************************************************************************/
/*!
 * Get the current PLL VCO frequency configuration.
 *
 * \param       pll
 *              The PLL to get the VCO frequency configuration for.
 *
 * \param       mult
 *              [out] Pointer to an output variable for the returned
 *              configured PLL VCO multiplier (M) value.
 *
 * \param       div
 *              [out] Pointer to an output variable for the returned
 *              configured PLL VCO divider (N) value.
 *
 * \retval      ALT_E_SUCCESS   The operation was succesful.
 * \retval      ALT_E_ERROR     The operation failed.
 */
ALT_STATUS_CODE alt_clk_pll_vco_cfg_get(ALT_CLK_t pll,
                                        uint32_t* mult,
                                        uint32_t* div);

/******************************************************************************/
/*!
 * Set the PLL VCO frequency configuration using the supplied multiplier and
 * divider arguments.
 *
 * \param       pll
 *              The PLL to set the VCO frequency configuration for.
 *
 * \param       mult
 *              The PLL VCO multiplier (M). Expected argument range 1 to 4096.
 *
 * \param       div
 *              The PLL VCO divider (N). Expected argument range 1 to 64.
 *
 * \retval      ALT_E_SUCCESS   The operation was succesful.
 * \retval      ALT_E_ERROR     The operation failed.
 */
ALT_STATUS_CODE alt_clk_pll_vco_cfg_set(ALT_CLK_t pll,
                                        uint32_t mult,
                                        uint32_t div);

/******************************************************************************/
/*!
 * Get the VCO frequency of the specified PLL.
 *
 * \param       pll
 *              The PLL to retrieve the VCO frequency from.
 *
 * \param       freq
 *              [out] Pointer to the an output parameter variable to return the
 *              PLL VCO frequency value. The frequency value is returned as a
 *              measures of Hz.
 *
 * \retval      ALT_E_SUCCESS   The operation was succesful.
 * \retval      ALT_E_ERROR     The operation failed.
 * \retval      ALT_E_BAD_ARG   A bad argument value was passed. Either
 *                              the \e pll argument is invalid or a bad
 *                              \e freq pointer value was passed.
 */
ALT_STATUS_CODE alt_clk_pll_vco_freq_get(ALT_CLK_t pll,
                                         alt_freq_t* freq);

/******************************************************************************/
/*!
 * Get the PLL frequency guard band value.
 *
 * \param       pll
 *              The PLL from which to return the current guard band value.
 *
 * \returns     The current guard band range in effect for the PLL.
 */
uint32_t alt_clk_pll_guard_band_get(ALT_CLK_t pll);

/******************************************************************************/
/*!
 * Set the PLL frequency guard band value.
 *
 * Once a PLL has achieved lock, any changes to the PLL VCO frequency that are
 * within a specific guard band range (default value 20%) of the reference
 * period should not cause the PLL to lose lock.
 *
 * Programmatic changes to the PLL frequency within this guard band range are
 * permitted to be made without the risk of breaking lock during the transition
 * to the new frequency.
 *
 * The clk_mgr_pll_guard_band_set() function changes the guard band from its
 * current value to permit a more lenient or stringent policy to be in effect in
 * the implementation of the functions configuring PLL VCO frequency. The
 * rationale for changing the default guard band value might be to accommodate
 * unexpected environmental conditions (noise, temperature, and other
 * instability factors) that may affect the PLLs ability to maintain lock during
 * a frequency change.
 *
 * \param       pll
 *              The PLL to set the guard band value for.
 *
 * \param       guard_band
 *              The guard band value. Value should be 0 <= \e guard_band <= 100.
 *
 * \retval      ALT_E_SUCCESS   The operation was succesful.
 * \retval      ALT_E_ERROR     The operation failed.
 * \retval      ALT_E_ARG_RANGE The guard band value violates its range constraint.
 */
ALT_STATUS_CODE alt_clk_pll_guard_band_set(ALT_CLK_t pll,
                                           uint32_t guard_band);

/******************************************************************************/
/*!
 * Get the configured divider value for the specified clock.
 *
 * This function is used to get the configured values of both internal and
 * external clock dividers.  The internal divider (PLL counters C0-C5) values
 * are retrieved by specifying the clock name that is the divider output
 * (e.g. ALT_CLK_MPU is used to get the Main PLL C0 counter value). \n
 * It returns the actual divider value, not the encoded bitfield stored
 * in the register, due to the variety of different encodings.
 *
 * \param       clk
 *              The clock divider to get the value from.
 *
 * \param       div
 *              [out] Pointer to an output variable for the returned clock
 *              divider value.
 *
 * \retval      ALT_E_SUCCESS   The operation was succesful.
 * \retval      ALT_E_ERROR     The operation failed.
 * \retval      ALT_E_BAD_ARG   An invalid clock argument was specified or a
 *                              clock that does not have a divider.
 */
ALT_STATUS_CODE alt_clk_divider_get(ALT_CLK_t clk,
                                    uint32_t* div);

/******************************************************************************/
/*!
 * Set the divider value for the specified clock.
 *
 * This function is used to set the values of both internal and external clock
 * dividers.  The internal divider (PLL counters C0-C5) values are set by
 * specifying the clock name that is the divider output (e.g. ALT_CLK_MPU is
 * used to set the Main PLL C0 counter value).
 *
 * \param       clk
 *              The clock divider to set the value for.
 *
 * \param       div
 *              The clock divider value. NOTE: The valid range of clock divider
 *              values depends on the clock being configured. This is the
 *              real divisor ratio, not how the divisor is coded into the
 *              register, and is always one or greater.
 *
 * \retval      ALT_E_SUCCESS   The operation was succesful.
 * \retval      ALT_E_ERROR     The operation failed.
 * \retval      ALT_E_BAD_ARG   An invalid clock argument was specified or a
 *                              clock that does not have a divider.
 * \retval      ALT_E_ARG_RANGE The divider value violates the range constraints
 *                              for the clock divider.
 */
ALT_STATUS_CODE alt_clk_divider_set(ALT_CLK_t clk,
                                    uint32_t div);

/******************************************************************************/
/*!
 * Get the output frequency of the specified clock.
 *
 * \param       clk
 *              The clock to retrieve the output frequency from.
 *
 * \param       freq
 *              [out] Pointer to the an output parameter variable to return the
 *              clock output frequency value. The frequency value is returned as
 *              a measures of Hz.
 *
 * \retval      ALT_E_SUCCESS   The operation was succesful.
 * \retval      ALT_E_ERROR     The operation failed.
 * \retval      ALT_E_BAD_ARG   A bad argument value was passed. Either
 *                              the \e clk argument is invalid or a bad
 *                              \e freq pointer value was passed.
 */
ALT_STATUS_CODE alt_clk_freq_get(ALT_CLK_t clk,
                                 alt_freq_t* freq);

/*! @} */

/******************************************************************************/
/*! \addtogroup CLK_MGR_INT Clock Manager Interrupt Management
 *
 * The functions in this group provide management of interrupts originating from
 * the Clock Manager.
 *
 * The following interrupt request (IRQ) signals are sourced from the Clock
 * Manager:
 *
 * * \b clkmgr_IRQ - Clock Manager lock status interrupt output.  The PLL lock
 *                   status interrupt is the logical \e OR of six interrupt
 *                   sources defining the loss or achievement of lock status for
 *                   each PLL. The six PLL lock status conditions are:
 *                   - Main PLL Achieved Lock
 *                   - Main PLL Lost Lock
 *                   - Peripheral PLL Achieved Lock
 *                   - Peripheral PLL Lost Lock
 *                   - SDRAM PLL Achieved Lock
 *                   - SDRAM PLL Lost Lock
 *
 *                   They are enumeratated by the type \ref ALT_CLK_PLL_LOCK_STATUS_t.
 *
 *                   Each PLL lock condition may be individually disabled/enabled
 *                   as a contributor to the determination of the \b clkmgr_IRQ
 *                   assertion status.
 *
 *                   The alt_clk_lock_status_clear() function is used to clear
 *                   the PLL lock conditions causing the \b clkmgr_IRQ
 *                   assertion.
 *
 * * \b mpuwakeup_IRQ - MPU wakeup interrupt output. This interrupt notifies the
 *                      MPU to "wake up" after a transition of the Main PLL into
 *                      or out of bypass mode has been safely achieved. The need
 *                      for the "wake up" notification is because the PLL clocks
 *                      pause for a short number of clock cycles during bypass
 *                      state transition. ARM recommeds that the CPUs are placed
 *                      in standby if the clocks are ever paused.
 *
 * NOTE: \b mpuwakeup_IRQ appears to be an Altera private interrupt and may not
 *        be part of the public API although clearly it has important utility in
 *        implementing safe changes to PLL settings and transitions into and out
 *        of bypass mode.
 * @{
 */

/******************************************************************************/
/*!
 * Disable the \b clkmgr_IRQ interrupt signal source lock status condition(s).
 *
 * This function disables one or more of the lock status conditions as
 * contributors to the \b clkmgr_IRQ interrupt signal state.
 *
 * NOTE: A set bit for a PLL lock status condition in the mask value does not
 * have the effect of enabling it as a contributor to the \b clkmgr_IRQ
 * interrupt signal state. The function alt_clk_irq_enable is used to enable PLL
 * lock status source condition(s).
 *
 * \param       lock_stat_mask
 *              Specifies the PLL lock status conditions to disable as interrupt
 *              source contributors. \e lock_stat_mask is a mask of logically
 *              OR'ed ALT_CLK_PLL_LOCK_STATUS_t values that designate the PLL lock
 *              conditions to disable.
 *
 * \retval      ALT_E_SUCCESS   Successful status.
 * \retval      ALT_E_BAD_ARG   The \e lock_stat_mask argument contains an
 *                              unknown condition value.
 */
ALT_STATUS_CODE alt_clk_irq_disable(ALT_CLK_PLL_LOCK_STATUS_t lock_stat_mask);

/******************************************************************************/
/*!
 * Enable the \b clkmgr_IRQ interrupt signal source lock status condition(s).
 *
 * This function enables one or more of the lock status conditions as
 * contributors to the \b clkmgr_IRQ interrupt signal state.
 *
 * NOTE: A cleared bit for any PLL lock status condition in the mask value does
 * not have the effect of disabling it as a contributor to the \b clkmgr_IRQ
 * interrupt signal state. The function alt_clk_irq_disable is used to disable
 * PLL lock status source condition(s).
 *
 * \param       lock_stat_mask
 *              Specifies the PLL lock status conditions to enable as interrupt
 *              source contributors. \e lock_stat_mask is a mask of logically
 *              OR'ed ALT_CLK_PLL_LOCK_STATUS_t values that designate the PLL lock
 *              conditions to enable.
 *
 * \retval      ALT_E_SUCCESS   Successful status.
 * \retval      ALT_E_BAD_ARG   The \e lock_stat_mask argument contains an
 *                              unknown condition value.
 */
ALT_STATUS_CODE alt_clk_irq_enable(ALT_CLK_PLL_LOCK_STATUS_t lock_stat_mask);

/*! @} */

/******************************************************************************/
/*! \addtogroup CLK_MGR_GROUP_CFG Clock Group Configuration
 *
 * This API provides the ability to safely set the configuration of a clock
 * group with a single function call.
 *
 * A clock group is defined as set of clocks and signals generated from a common
 * PLL VCO. The PLL and its derived clocks are treated as a single clock
 * group. The clocks sourced directly or indirectly from the PLL may or may not
 * have these features:
 * * Clock Gates
 * * Clock Dividers
 * * Clock Source Selection Options
 *
 * The use case for application of the Clock Group Configuration functions is the
 * ability to safely configure an entire clock group from a known good clock
 * group configuration using the run-time function alt_clk_group_cfg_raw_set().
 *
 * A known good clock group configuration may be generated by one of the
 * following methods:
 *
 * * As static design information generated by an ACDS clock configuration tool
 *   and passed to embedded software for dynamic loading.
 *
 * * By calling alt_clk_group_cfg_raw_get() at run-time from an SoC FPGA that has
 *   programmatically established a known good clock group configuration using
 *   the clock manager API configuration functions.
 *
 * @{
 */

/******************************************************************************/
/*!
 * Get the raw configuration state of the designated clock group.
 *
 * This function is used to capture the configuration state of the specified
 * clock group in a private (raw) data structure.  The raw data structure may be
 * saved and used later to restore the clock group configuration using
 * alt_clk_group_cfg_raw_get().
 *
 * \param       clk_group
 *              The clock group configuration to capture.
 *
 * \param       clk_group_raw_cfg
 *              [out] A pointer to a private (raw) data structure to store the
 *              captured clock group configuration.
 *
 * \retval      ALT_E_SUCCESS   Successful status.
 * \retval      ALT_E_ERROR     Details about error status code
 */
ALT_STATUS_CODE alt_clk_group_cfg_raw_get(ALT_CLK_GRP_t clk_group,
                                          ALT_CLK_GROUP_RAW_CFG_t* clk_group_raw_cfg);

/******************************************************************************/
/*!
 * Set the clock group configuration.
 *
 * This function is used to safely set the configuration state of a clock
 * group from a raw clock group configuration specification.  The raw clock
 * group configuration specification may be a configuration previously
 * captured with alt_clk_group_cfg_raw_get() or a group clock configuration
 * generated by an external utility.
 *
 * \param       clk_group_raw_cfg
 *              A pointer to the specification to use in the configuration of
 *              the clock group.
 *
 * \retval      ALT_E_SUCCESS       Successful status.
 * \retval      ALT_E_ERROR         Details about error status code
 * \retval      ALT_E_BAD_VERSION   The clock group configuration specification is
 *                                  invalid for this device.
 */
ALT_STATUS_CODE alt_clk_group_cfg_raw_set(const ALT_CLK_GROUP_RAW_CFG_t* clk_group_raw_cfg);

ALT_STATUS_CODE alt_clk_clkmgr_init(void);

/*! @} */

/*! @} */
#ifdef __cplusplus
}

#endif  /* __cplusplus */
#endif  /* __ALT_CLK_MGR_H__ */