PDL for FM4  Version1.2
Peripheral Driverl Library for FM4
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,
228 
239 typedef enum en_clk_mode
240 {
241  ClkRun = 0,
242  ClkSleep = 1,
243  ClkTimer = 2,
244  ClkStop = 3,
245  ClkRtc = 4,
248 } en_clk_mode_t;
249 
256 typedef enum en_clk_baseclkdiv
257 {
267 
274 typedef enum en_clk_apb0div
275 {
276  Apb0Div1 = 0,
277  Apb0Div2 = 1,
278  Apb0Div4 = 2,
279  Apb0Div8 = 3
281 
288 typedef enum en_clk_apb1div
289 {
290  Apb1Div1 = 0,
291  Apb1Div2 = 1,
292  Apb1Div4 = 2,
293  Apb1Div8 = 3
295 
302 typedef enum en_clk_apb2div
303 {
304  Apb2Div1 = 0,
305  Apb2Div2 = 1,
306  Apb2Div4 = 2,
307  Apb2Div8 = 3
309 
316 typedef enum en_clk_scowaittime
317 {
332 
339 typedef enum en_clk_mcowaittime
340 {
358 
366 {
376 
387 typedef enum en_clk_pll_src
388 {
390  PllSrcClkHc = 123
392 
397 #if (PDL_INTERRUPT_ENABLE_CLK == PDL_ON)
398 typedef struct stc_clk_intern_data
399 {
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,
420 
425 typedef enum en_clk_boost_time
426 {
432 
437 typedef enum en_clk_vbat_pins
438 {
443 
449 {
454 
460 {
471  ClkGateMfs3 = 10,
472  ClkGateMfs4 = 11,
473  ClkGateMfs5 = 12,
474  ClkGateMfs6 = 13,
475  ClkGateMfs7 = 14,
476  ClkGateMfs8 = 15,
477  ClkGateMfs9 = 16,
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,
502 
508 {
539  ClkResetBt0 = 31,
540  ClkResetBt4 = 32,
541  ClkResetBt8 = 33,
549 
556 typedef struct stc_clk_main_config
557 {
563 
564 
573  uint8_t u8PllK;
574  uint8_t u8PllM;
575  uint8_t u8PllN;
577 #if (PDL_INTERRUPT_ENABLE_CLK == PDL_ON)
582 #endif
585 
592 typedef struct stc_clk_sub_config
593 {
596 #if (PDL_INTERRUPT_ENABLE_CLK == PDL_ON)
599 #endif
601 
608 typedef struct stc_clk_vbat_config
609 {
611 
612  uint8_t u8VbClockDiv;
632 
633 /******************************************************************************/
634 /* Global variable definitions ('extern') */
635 /******************************************************************************/
636 #if (PDL_INTERRUPT_ENABLE_CLK == PDL_ON)
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 
651 
653 
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 
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 
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 
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 
693 
695 
697 
699 
701 
703 
705 
706 extern en_result_t Clk_SwitchToMainClock(void) ;
707 
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 
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 /******************************************************************************/