PDL for FM4
Version1.2
Peripheral Driverl Library for FM4
Main Page
Modules
Data Structures
Files
File List
Globals
clk.h
Go to the documentation of this file.
1
/*******************************************************************************
2
* Copyright (C) 2013 Spansion LLC. All Rights Reserved.
3
*
4
* This software is owned and published by:
5
* Spansion LLC, 915 DeGuigne Dr. Sunnyvale, CA 94088-3453 ("Spansion").
6
*
7
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
8
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
9
*
10
* This software contains source code for use with Spansion
11
* components. This software is licensed by Spansion to be adapted only
12
* for use in systems utilizing Spansion components. Spansion shall not be
13
* responsible for misuse or illegal use of this software for devices not
14
* supported herein. Spansion is providing this software "AS IS" and will
15
* not be responsible for issues arising from incorrect user implementation
16
* of the software.
17
*
18
* SPANSION MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
19
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
20
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
21
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
22
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
23
* WARRANTY OF NONINFRINGEMENT.
24
* SPANSION SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
25
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
26
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
27
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
28
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
29
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
30
* SAVINGS OR PROFITS,
31
* EVEN IF SPANSION HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
32
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
33
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
34
* FROM, THE SOFTWARE.
35
*
36
* This software may be replicated in part or whole for the licensed use,
37
* with the restriction that this Disclaimer and Copyright notice must be
38
* included with each copy of this software, whether used in part or whole,
39
* at all times.
40
*/
41
/******************************************************************************/
53
#ifndef __CLK_H__
54
#define __CLK_H__
55
56
/******************************************************************************/
57
/* Include files */
58
/******************************************************************************/
59
#include "
pdl.h
"
60
61
#if (defined(PDL_PERIPHERAL_CLK_ACTIVE))
62
63
/* C binding of definitions if building with C++ compiler */
64
#ifdef __cplusplus
65
extern
"C"
66
{
67
#endif
68
153
154
/******************************************************************************/
155
/* Global pre-processor symbols/macros ('#define') */
156
/******************************************************************************/
157
#define CLK_SUBCLK_TRANSITION_TIMEOUT 100000000u // Counter for VBAT transition time out
158
159
#define PLLK_MAX 4u // Setting according Peripheral Manual
160
#define PLLN_MAX 40u // Setting according Peripheral Manual
161
#define PLLM_MAX 4u // Setting according Peripheral Manual
162
163
#define BSC_PSR_MAX 0x06u
164
#define APBC0_PSR_MAX 0x03u
165
#define APBC1_PSR_MAX 0x03u
166
#define APBC2_PSR_MAX 0x03u
167
#define CSW_TMR_SOWT_MAX 0x0Bu
168
#define CSW_TMR_MOWT_MAX 0x0Fu
169
#define PSW_TMR_POWT_MAX 0x07u
170
#define PLL_CTL1_PLLK_MAX ((uint8_t)PLLK_MAX)
171
#define PLL_CTL1_PLLM_MAX ((uint8_t)PLLM_MAX)
172
#define PLL_CTL2_PLLN_MAX ((uint8_t)PLLN_MAX)
173
174
// Driver's own SCB_SCR definition to stay compatible for IAR and KEIL!
175
#define CLK_SCB_SCR *(volatile uint32_t*) 0xE000ED10ul
176
#define CLK_SCB_SCR_SLEEPDEEP_Position 2u // SCB SCR: SLEEPDEEP Position
177
#define CLK_SCB_SCR_SLEEPDEEP_Mask (1ul << CLK_SCB_SCR_SLEEPDEEP_Position) // SCB SCR: SLEEPDEEP Mask
178
179
// Driver's own PMD_CTL address definition
180
#define FM4_PMD_CTL *(volatile uint8_t*) 0x40035800ul
181
182
// Deep Standby Mode Select (DSTM) Bit Position
183
#define FM4_STB_CTL_DSTM_BITPOS 0x00000004ul
184
185
// PLL Input Clock Select (PINC) Bit Position
186
#define FM4_PSW_TMR_PINC_BITPOS 0x10u
187
188
// Interrupt enable bitpositions in INT_ENR
189
#define FM4_INT_ENR_PCSE_BITPOS 0x04u
190
#define FM4_INT_ENR_SCSE_BITPOS 0x02u
191
#define FM4_INT_ENR_MCSE_BITPOS 0x01u
192
193
// Interrupt status bitpositions in INT_STR
194
#define FM4_INT_STR_PCSI_BITPOS 0x04u
195
#define FM4_INT_STR_SCSI_BITPOS 0x02u
196
#define FM4_INT_STR_MCSI_BITPOS 0x01u
197
198
// Interrupt ckear bitpositions in INT_CLR
199
#define FM4_INT_CLR_PCSC_BITPOS 0x04u
200
#define FM4_INT_CLR_SCSC_BITPOS 0x02u
201
#define FM4_INT_CLR_MCSC_BITPOS 0x01u
202
203
/******************************************************************************
204
* Global type definitions
205
******************************************************************************/
206
219
typedef
enum
en_clk_source
220
{
221
ClkMain
= 0,
222
ClkSub
= 1,
223
ClkHsCr
= 2,
224
ClkLsCr
= 3,
225
ClkPll
= 4,
226
ClkHsCrPll
= 5
227
}
en_clk_source_t
;
228
239
typedef
enum
en_clk_mode
240
{
241
ClkRun
= 0,
242
ClkSleep
= 1,
243
ClkTimer
= 2,
244
ClkStop
= 3,
245
ClkRtc
= 4,
246
ClkDeepRtc
= 5,
247
ClkDeepStop
= 6
248
}
en_clk_mode_t
;
249
256
typedef
enum
en_clk_baseclkdiv
257
{
258
BaseClkDiv1
= 0,
259
BaseClkDiv2
= 1,
260
BaseClkDiv3
= 2,
261
BaseClkDiv4
= 3,
262
BaseClkDiv6
= 4,
263
BaseClkDiv8
= 5,
264
BaseClkDiv16
= 6,
265
BaseClkErr
= 7
266
}
en_clk_baseclkdiv_t
;
267
274
typedef
enum
en_clk_apb0div
275
{
276
Apb0Div1
= 0,
277
Apb0Div2
= 1,
278
Apb0Div4
= 2,
279
Apb0Div8
= 3
280
}
en_clk_apb0div_t
;
281
288
typedef
enum
en_clk_apb1div
289
{
290
Apb1Div1
= 0,
291
Apb1Div2
= 1,
292
Apb1Div4
= 2,
293
Apb1Div8
= 3
294
}
en_clk_apb1div_t
;
295
302
typedef
enum
en_clk_apb2div
303
{
304
Apb2Div1
= 0,
305
Apb2Div2
= 1,
306
Apb2Div4
= 2,
307
Apb2Div8
= 3
308
}
en_clk_apb2div_t
;
309
316
typedef
enum
en_clk_scowaittime
317
{
318
ScoWaitExp10
= 0,
319
ScoWaitExp11
= 1,
320
ScoWaitExp12
= 2,
321
ScoWaitExp13
= 3,
322
ScoWaitExp14
= 4,
323
ScoWaitExp15
= 5,
324
ScoWaitExp16
= 6,
325
ScoWaitExp17
= 7,
326
ScoWaitExp18
= 8,
327
ScoWaitExp19
= 9,
328
ScoWaitExp20
= 10,
329
ScoWaitExp21
= 11,
330
ScoWaitErr
= 12
331
}
en_clk_scowaittime_t
;
332
339
typedef
enum
en_clk_mcowaittime
340
{
341
McoWaitExp11
= 0,
342
McoWaitExp15
= 1,
343
McoWaitExp16
= 2,
344
McoWaitExp17
= 3,
345
McoWaitExp18
= 4,
346
McoWaitExp19
= 5,
347
McoWaitExp110
= 6,
348
McoWaitExp111
= 7,
349
McoWaitExp112
= 8,
350
McoWaitExp113
= 9,
351
McoWaitExp114
= 10,
352
McoWaitExp115
= 11,
353
McoWaitExp117
= 12,
354
McoWaitExp119
= 13,
355
McoWaitExp121
= 14,
356
McoWaitExp123
= 15
357
}
en_clk_mcowaittime_t
;
358
365
typedef
enum
en_clk_pllowaittime
366
{
367
PlloWaitExp19
= 0,
368
PlloWaitExp110
= 1,
369
PlloWaitExp111
= 2,
370
PlloWaitExp112
= 3,
371
PlloWaitExp113
= 4,
372
PlloWaitExp114
= 5,
373
PlloWaitExp115
= 6,
374
PlloWaitExp116
= 7
375
}
en_clk_pllowaittime_t
;
376
387
typedef
enum
en_clk_pll_src
388
{
389
PllSrcClkMo
= 0,
390
PllSrcClkHc
= 123
391
}
en_clk_pll_src_t
;
392
397
#if (PDL_INTERRUPT_ENABLE_CLK == PDL_ON)
398
typedef
struct
stc_clk_intern_data
399
{
400
func_ptr_t
pfnPllStabCb
;
401
func_ptr_t
pfnScoStabCb
;
402
func_ptr_t
pfnMcoStabCb
;
403
}
stc_clk_intern_data_t
;
404
#endif
405
410
typedef
enum
en_clk_current
411
{
412
Clk0nA
= 0,
413
Clk135nA
= 1,
414
Clk195nA
= 2,
415
Clk385nA
= 3,
416
Clk445nA
= 4,
417
Clk510nA
= 5,
418
ClkErrorCurrent
= 6
419
}
en_clk_current_t
;
420
425
typedef
enum
en_clk_boost_time
426
{
427
ClkBoost50ms
= 0,
428
ClkBoost63ms
= 1,
429
ClkBoost125ms
= 2,
430
ClkBoost250ms
= 3
431
}
en_clk_boost_time_t
;
432
437
typedef
enum
en_clk_vbat_pins
438
{
439
ClkVbatGpio
= 0,
440
ClkVbatOsc
= 1,
441
ClkVbatGpioOsc
= 2
442
}
en_clk_vbat_pins_t
;
443
448
typedef
enum
en_clk_vbat_pins_ddr
449
{
450
ClkVbatInput
= 0,
451
ClkVbatOutputL
= 1,
452
ClkVbatOutputH
= 2
453
}
en_clk_vbat_pins_ddr_t
;
454
459
typedef
enum
en_clk_gate_peripheral
460
{
461
ClkGateGpio
= 0,
462
ClkGateExtif
= 1,
463
ClkGateDma
= 2,
464
ClkGateAdc0
= 3,
465
ClkGateAdc1
= 4,
466
ClkGateAdc2
= 5,
467
ClkGateAdc3
= 6,
468
ClkGateMfs0
= 7,
469
ClkGateMfs1
= 8,
470
ClkGateMfs2
= 9,
471
ClkGateMfs3
= 10,
472
ClkGateMfs4
= 11,
473
ClkGateMfs5
= 12,
474
ClkGateMfs6
= 13,
475
ClkGateMfs7
= 14,
476
ClkGateMfs8
= 15,
477
ClkGateMfs9
= 16,
478
ClkGateMfs10
= 17,
479
ClkGateMfs11
= 18,
480
ClkGateMfs12
= 19,
481
ClkGateMfs13
= 20,
482
ClkGateMfs14
= 21,
483
ClkGateMfs15
= 22,
484
ClkGateQprc0
= 23,
485
ClkGateQprc1
= 24,
486
ClkGateQprc2
= 25,
487
ClkGateQprc3
= 26,
488
ClkGateMft0
= 27,
489
ClkGateMft1
= 28,
490
ClkGateMft2
= 29,
491
ClkGateMft3
= 30,
492
ClkGateBt0
= 31,
493
ClkGateBt4
= 32,
494
ClkGateBt8
= 33,
495
ClkGateBt12
= 34,
496
ClkGateSdIf
= 35,
497
ClkGateCan0
= 36,
498
ClkGateCan1
= 37,
499
ClkGateUsb0
= 38,
500
ClkGateUsb1
= 39
501
}
en_clk_gate_peripheral_t
;
502
507
typedef
enum
en_clk_reset_peripheral
508
{
509
ClkResetExtif
= 1,
510
ClkResetDma
= 2,
511
ClkResetAdc0
= 3,
512
ClkResetAdc1
= 4,
513
ClkResetAdc2
= 5,
514
ClkResetAdc3
= 6,
515
ClkResetMfs0
= 7,
516
ClkResetMfs1
= 8,
517
ClkResetMfs2
= 9,
518
ClkResetMfs3
= 10,
519
ClkResetMfs4
= 11,
520
ClkResetMfs5
= 12,
521
ClkResetMfs6
= 13,
522
ClkResetMfs7
= 14,
523
ClkResetMfs8
= 15,
524
ClkResetMfs9
= 16,
525
ClkResetMfs10
= 17,
526
ClkResetMfs11
= 18,
527
ClkResetMfs12
= 19,
528
ClkResetMfs13
= 20,
529
ClkResetMfs14
= 21,
530
ClkResetMfs15
= 22,
531
ClkResetQprc0
= 23,
532
ClkResetQprc1
= 24,
533
ClkResetQprc2
= 25,
534
ClkResetQprc3
= 26,
535
ClkResetMft0
= 27,
536
ClkResetMft1
= 28,
537
ClkResetMft2
= 29,
538
ClkResetMft3
= 30,
539
ClkResetBt0
= 31,
540
ClkResetBt4
= 32,
541
ClkResetBt8
= 33,
542
ClkResetBt12
= 34,
543
ClkResetSdIf
= 35,
544
ClkResetCan0
= 36,
545
ClkResetCan1
= 37,
546
ClkResetUsb0
= 38,
547
ClkResetUsb1
= 39
548
}
en_clk_reset_peripheral_t
;
549
556
typedef
struct
stc_clk_main_config
557
{
558
en_clk_source_t
enSource
;
559
boolean_t
bEnablePll
;
560
boolean_t
bEnableMainClock
;
561
en_clk_mode_t
enMode
;
562
boolean_t
bLpmPortHiZState
;
563
564
565
en_clk_baseclkdiv_t
enBaseClkDiv
;
566
en_clk_apb0div_t
enAPB0Div
;
567
en_clk_apb1div_t
enAPB1Div
;
568
en_clk_apb2div_t
enAPB2Div
;
569
boolean_t
bAPB1Disable
;
570
boolean_t
bAPB2Disable
;
571
en_clk_mcowaittime_t
enMCOWaitTime
;
572
en_clk_pllowaittime_t
enPLLOWaitTime
;
573
uint8_t
u8PllK
;
574
uint8_t
u8PllM
;
575
uint8_t
u8PllN
;
576
en_clk_pll_src_t
enPllSource
;
577
#if (PDL_INTERRUPT_ENABLE_CLK == PDL_ON)
578
boolean_t
bPllIrq
;
579
boolean_t
bMcoIrq
;
580
func_ptr_t
pfnPllStabCb
;
581
func_ptr_t
pfnMcoStabCb
;
582
#endif
583
func_ptr_t
pfnHook
;
584
}
stc_clk_main_config_t
;
585
592
typedef
struct
stc_clk_sub_config
593
{
594
boolean_t
bEnableSubClock
;
595
en_clk_scowaittime_t
enSCOWaitTime
;
596
#if (PDL_INTERRUPT_ENABLE_CLK == PDL_ON)
597
boolean_t
bScoIrq
;
598
func_ptr_t
pfnScoStabCb
;
599
#endif
600
}
stc_clk_sub_config_t
;
601
608
typedef
struct
stc_clk_vbat_config
609
{
610
boolean_t
bLinkClock
;
611
612
uint8_t
u8VbClockDiv
;
613
en_clk_current_t
enClkSustainCurrent
;
614
en_clk_current_t
enClkBoostCurrent
;
615
en_clk_boost_time_t
enClkBoostTime
;
616
en_clk_vbat_pins_t
enVbatPins
;
617
boolean_t
bVbP48Peripheral
;
618
boolean_t
bVbP49Peripheral
;
619
boolean_t
bVbP47Peripheral
;
620
boolean_t
bVbP46Peripheral
;
621
boolean_t
bVbP48PullUp
;
622
boolean_t
bVbP49PullUp
;
623
boolean_t
bVbP47PullUp
;
624
boolean_t
bVbP46PullUp
;
625
en_clk_vbat_pins_ddr_t
enVbP48InOut
;
626
en_clk_vbat_pins_ddr_t
enVbP49InOut
;
627
en_clk_vbat_pins_ddr_t
enVbP47InOut
;
628
en_clk_vbat_pins_ddr_t
enVbP46InOut
;
629
boolean_t
bVbP48OpenDrain
;
630
boolean_t
bVbP49OpenDrain
;
631
}
stc_clk_vbat_config_t
;
632
633
/******************************************************************************/
634
/* Global variable definitions ('extern') */
635
/******************************************************************************/
636
#if (PDL_INTERRUPT_ENABLE_CLK == PDL_ON)
637
extern
stc_clk_intern_data_t
stcClkInternData
;
638
#endif
639
640
/******************************************************************************/
641
/* Global function prototypes (definition in C source) */
642
/******************************************************************************/
643
644
#if (PDL_INTERRUPT_ENABLE_CLK == PDL_ON)
645
extern
void
ClkIrqHandler
(
void
) ;
646
#endif
647
648
extern
en_result_t
Clk_MainGetParameters
(
stc_clk_main_config_t
* pstcConfig) ;
649
extern
en_result_t
Clk_SubGetParameters
(
stc_clk_sub_config_t
* pstcConfig) ;
650
extern
en_result_t
Clk_VbatGetParameters
(
stc_clk_vbat_config_t
* pstcConfig) ;
651
652
extern
en_result_t
Clk_SetDividers
(
stc_clk_main_config_t
* pstcConfig) ;
653
654
extern
en_result_t
Clk_MainSetStabilizationWaitTime
(
stc_clk_main_config_t
* pstcConfig) ;
655
extern
en_result_t
Clk_SubSetStabilizationWaitTime
(
stc_clk_sub_config_t
* pstcConfig) ;
656
657
extern
en_result_t
Clk_WaitForMainOscillator
(uint32_t u32MaxTimeOut) ;
658
extern
en_result_t
Clk_WaitForSubOscillator
(uint32_t u32MaxTimeOut) ;
659
660
extern
en_result_t
Clk_WaitForPllOscillator
(uint32_t u32MaxTimeOut) ;
661
662
extern
en_result_t
Clk_MainOscillatorReady
(
void
) ;
663
extern
en_result_t
Clk_SubOscillatorReady
(
void
) ;
664
665
extern
en_result_t
Clk_PllOscillatorReady
(
void
) ;
666
667
extern
en_result_t
Clk_SetSource
(
stc_clk_main_config_t
* pstcConfigMain,
668
stc_clk_sub_config_t
* pstcConfigSub) ;
669
670
extern
en_result_t
Clk_SetPllSource
(
stc_clk_main_config_t
* pstcConfig) ;
671
672
extern
en_result_t
Clk_SetMode
(
stc_clk_main_config_t
* pstcConfig) ;
673
674
extern
en_result_t
Clk_EnableMainClock
(
void
) ;
675
extern
en_result_t
Clk_EnablePllClock
(
stc_clk_main_config_t
* pstcConfigMain) ;
676
extern
en_result_t
Clk_EnableSubClock
(
void
) ;
677
678
extern
en_result_t
Clk_DisableMainClock
(
void
) ;
679
extern
en_result_t
Clk_DisablePllClock
(
void
) ;
680
extern
en_result_t
Clk_DisableSubClock
(
void
) ;
681
682
extern
en_result_t
Clk_WaitForClockSourceReady
(
en_clk_source_t
enSource,
683
uint32_t u32MaxTimeOut) ;
684
685
#if (PDL_INTERRUPT_ENABLE_CLK == PDL_ON)
686
extern
en_result_t
Clk_SetIrq
(
stc_clk_main_config_t
* pstcConfigMain,
687
stc_clk_sub_config_t
* pstcConfigSub,
688
boolean_t
bTouchNvic
689
) ;
690
#endif
691
692
extern
en_result_t
Clk_ClockVbatInit
(
stc_clk_vbat_config_t
* pstcConfig) ;
693
694
extern
en_result_t
Clk_RequestVccPowerDown
(
void
) ;
695
696
extern
en_result_t
Clk_PeripheralClockEnable
(
en_clk_gate_peripheral_t
enPeripheral) ;
697
698
extern
boolean_t
Clk_PeripheralGetClockState
(
en_clk_gate_peripheral_t
enPeripheral) ;
699
700
extern
en_result_t
Clk_PeripheralClockDisable
(
en_clk_gate_peripheral_t
enPeripheral) ;
701
702
extern
en_result_t
Clk_PeripheralSetReset
(
en_clk_reset_peripheral_t
enPeripheral) ;
703
704
extern
en_result_t
Clk_PeripheralClearReset
(
en_clk_reset_peripheral_t
enPeripheral) ;
705
706
extern
en_result_t
Clk_SwitchToMainClock
(
void
) ;
707
708
extern
en_result_t
Clk_SwitchToMainPllClock
(
void
) ;
709
710
extern
en_result_t
Clk_SwitchToSubClock
(
void
) ;
711
712
extern
en_result_t
Clk_SwitchToLsCrClock
(
void
) ;
713
714
extern
en_result_t
Clk_SwitchToHsCrClock
(
void
) ;
715
716
extern
en_result_t
Clk_SwitchToHsCrPllClock
(
void
) ;
717
718
720
721
#ifdef __cplusplus
722
}
723
#endif
724
725
#endif // #if (defined(PDL_PERIPHERAL_CLK_ACTIVE))
726
727
#endif
/* __CLK_H__ */
728
/******************************************************************************/
729
/* EOF (not truncated) */
730
/******************************************************************************/
PDL_1_2
library
driver
clk
clk.h
Generated on Wed May 28 2014 09:28:10 for PDL for FM4 by
1.8.3.1