Robobo
pmc.h
1 /* ----------------------------------------------------------------------------
2  * SAM Software Package License
3  * ----------------------------------------------------------------------------
4  * Copyright (c) 2011-2012, Atmel Corporation
5  *
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following condition is met:
10  *
11  * - Redistributions of source code must retain the above copyright notice,
12  * this list of conditions and the disclaimer below.
13  *
14  * Atmel's name may not be used to endorse or promote products derived from
15  * this software without specific prior written permission.
16  *
17  * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
18  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
20  * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
21  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
23  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
24  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
25  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
26  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  * ----------------------------------------------------------------------------
28  */
29 #ifndef PMC_H_INCLUDED
30 #define PMC_H_INCLUDED
31 
32 #include "../chip.h"
33 
35 
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
39 
40 
43 #define PMC_MASK_STATUS0 (0xFFFFFFFC)
44 
46 #define PMC_MASK_STATUS1 (0xFFFFFFFF)
47 
49 #define PMC_TIMEOUT (2048)
50 
52 #define PMC_CKGR_MOR_KEY_VALUE CKGR_MOR_KEY(0x37)
53 
55 #define SUPC_KEY_VALUE ((uint32_t) 0xA5)
56 
58 #define PMC_XTAL_STARTUP_TIME (0x3F)
59 
61 #define PMC_FAST_STARTUP_Msk (0xFFFFu)
62 
64 #define PMC_WPMR_WPKEY_VALUE PMC_WPMR_WPKEY((uint32_t) 0x504D43)
65 
67 #define PMC_OSC_XTAL 0
68 
70 #define PMC_OSC_BYPASS 1
71 
72 #define PMC_PCK_0 0 /* PCK0 ID */
73 #define PMC_PCK_1 1 /* PCK1 ID */
74 #define PMC_PCK_2 2 /* PCK2 ID */
75 
83 
84 void pmc_mck_set_prescaler(uint32_t ul_pres);
85 void pmc_mck_set_source(uint32_t ul_source);
86 uint32_t pmc_switch_mck_to_sclk(uint32_t ul_pres);
87 uint32_t pmc_switch_mck_to_mainck(uint32_t ul_pres);
88 uint32_t pmc_switch_mck_to_pllack(uint32_t ul_pres);
89 #if (SAM3S_SERIES || SAM4S_SERIES)
90 uint32_t pmc_switch_mck_to_pllbck(uint32_t ul_pres);
91 #endif
92 #if (SAM3XA_SERIES || SAM3U_SERIES)
93 uint32_t pmc_switch_mck_to_upllck(uint32_t ul_pres);
94 #endif
95 
97 
103 
104 void pmc_switch_sclk_to_32kxtal(uint32_t ul_bypass);
105 uint32_t pmc_osc_is_ready_32kxtal(void);
106 
108 
114 
115 void pmc_switch_mainck_to_fastrc(uint32_t ul_moscrcf);
116 void pmc_osc_enable_fastrc(uint32_t ul_rc);
117 void pmc_osc_disable_fastrc(void);
118 void pmc_switch_mainck_to_xtal(uint32_t ul_bypass);
119 void pmc_osc_disable_xtal(uint32_t ul_bypass);
120 uint32_t pmc_osc_is_ready_mainck(void);
121 
123 
129 
130 void pmc_enable_pllack(uint32_t mula, uint32_t pllacount, uint32_t diva);
131 void pmc_disable_pllack(void);
132 uint32_t pmc_is_locked_pllack(void);
133 
134 #if (SAM3S_SERIES || SAM4S_SERIES)
135 void pmc_enable_pllbck(uint32_t mulb, uint32_t pllbcount, uint32_t divb);
136 void pmc_disable_pllbck(void);
137 uint32_t pmc_is_locked_pllbck(void);
138 #endif
139 
140 #if (SAM3XA_SERIES || SAM3U_SERIES)
141 void pmc_enable_upll_clock(void);
142 void pmc_disable_upll_clock(void);
143 uint32_t pmc_is_locked_upll(void);
144 #endif
145 
147 
153 
154 uint32_t pmc_enable_periph_clk(uint32_t ul_id);
155 uint32_t pmc_disable_periph_clk(uint32_t ul_id);
156 void pmc_enable_all_periph_clk(void);
157 void pmc_disable_all_periph_clk(void);
158 uint32_t pmc_is_periph_clk_enabled(uint32_t ul_id);
159 
161 
169 
170 void pmc_pck_set_prescaler(uint32_t ul_id, uint32_t ul_pres);
171 void pmc_pck_set_source(uint32_t ul_id, uint32_t ul_source);
172 uint32_t pmc_switch_pck_to_sclk(uint32_t ul_id, uint32_t ul_pres);
173 uint32_t pmc_switch_pck_to_mainck(uint32_t ul_id, uint32_t ul_pres);
174 uint32_t pmc_switch_pck_to_pllack(uint32_t ul_id, uint32_t ul_pres);
175 #if (SAM3S_SERIES || SAM4S_SERIES)
176 uint32_t pmc_switch_pck_to_pllbck(uint32_t ul_id, uint32_t ul_pres);
177 #endif
178 #if (SAM3XA_SERIES || SAM3U_SERIES)
179 uint32_t pmc_switch_pck_to_upllck(uint32_t ul_id, uint32_t ul_pres);
180 #endif
181 void pmc_enable_pck(uint32_t ul_id);
182 void pmc_disable_pck(uint32_t ul_id);
183 void pmc_enable_all_pck(void);
184 void pmc_disable_all_pck(void);
185 uint32_t pmc_is_pck_enabled(uint32_t ul_id);
186 
188 
194 
195 #if (SAM3S_SERIES || SAM3XA_SERIES || SAM4S_SERIES)
196 void pmc_switch_udpck_to_pllack(uint32_t ul_usbdiv);
197 #endif
198 #if (SAM3S_SERIES || SAM4S_SERIES)
199 void pmc_switch_udpck_to_pllbck(uint32_t ul_usbdiv);
200 #endif
201 #if (SAM3XA_SERIES)
202 void pmc_switch_udpck_to_upllck(uint32_t ul_usbdiv);
203 #endif
204 #if (SAM3S_SERIES || SAM3XA_SERIES || SAM4S_SERIES)
205 void pmc_enable_udpck(void);
206 void pmc_disable_udpck(void);
207 #endif
208 
210 
216 
217 void pmc_enable_interrupt(uint32_t ul_sources);
218 void pmc_disable_interrupt(uint32_t ul_sources);
219 uint32_t pmc_get_interrupt_mask(void);
220 uint32_t pmc_get_status(void);
221 
223 
231 
232 void pmc_set_fast_startup_input(uint32_t ul_inputs);
233 void pmc_clr_fast_startup_input(uint32_t ul_inputs);
234 void pmc_enable_sleepmode(uint8_t uc_type);
235 void pmc_enable_waitmode(void);
236 void pmc_enable_backupmode(void);
237 
239 
245 
246 void pmc_set_writeprotect(uint32_t ul_enable);
247 uint32_t pmc_get_writeprotect_status(void);
248 
250 
252 
253 #ifdef __cplusplus
254 }
255 #endif
256 
257 
260 
424 #endif /* PMC_H_INCLUDED */
void pmc_switch_mainck_to_xtal(uint32_t ul_bypass)
Switch main clock source selection to external Xtal/Bypass. The function may switch MCK to SCLK if MC...
Definition: pmc.c:355
void pmc_enable_all_pck(void)
Enable all programmable clocks.
Definition: pmc.c:812
void pmc_disable_all_pck(void)
Disable all programmable clocks.
Definition: pmc.c:820
uint32_t pmc_get_interrupt_mask(void)
Get PMC interrupt mask.
Definition: pmc.c:929
void pmc_enable_interrupt(uint32_t ul_sources)
Enable PMC interrupts.
Definition: pmc.c:909
uint32_t pmc_is_periph_clk_enabled(uint32_t ul_id)
Check if the specified peripheral clock is enabled.
Definition: pmc.c:609
void pmc_switch_sclk_to_32kxtal(uint32_t ul_bypass)
Switch slow clock source selection to external 32k (Xtal or Bypass).
Definition: pmc.c:258
uint32_t pmc_switch_mck_to_pllack(uint32_t ul_pres)
Switch master clock source selection to PLLA clock.
Definition: pmc.c:155
void pmc_clr_fast_startup_input(uint32_t ul_inputs)
Clear the wake-up inputs for fast startup mode registers (remove event generation).
Definition: pmc.c:960
void pmc_mck_set_prescaler(uint32_t ul_pres)
Set the prescaler of the MCK.
Definition: pmc.c:67
void pmc_osc_disable_xtal(uint32_t ul_bypass)
Disable the external Xtal.
Definition: pmc.c:378
void pmc_osc_enable_fastrc(uint32_t ul_rc)
Enable fast RC oscillator.
Definition: pmc.c:325
uint32_t pmc_get_writeprotect_status(void)
Return write protect status.
Definition: pmc.c:1035
uint32_t pmc_enable_periph_clk(uint32_t ul_id)
Enable the specified peripheral clock.
Definition: pmc.c:518
void pmc_enable_all_periph_clk(void)
Enable all peripheral clocks.
Definition: pmc.c:574
void pmc_disable_interrupt(uint32_t ul_sources)
Disable PMC interrupts.
Definition: pmc.c:919
void pmc_enable_waitmode(void)
Enable Wait Mode. Enter condition: WFE + (SLEEPDEEP bit = 0) + (LPM bit = 1)
Definition: pmc.c:988
void pmc_set_fast_startup_input(uint32_t ul_inputs)
Set the wake-up inputs for fast startup mode registers (event generation).
Definition: pmc.c:949
void pmc_enable_pllack(uint32_t mula, uint32_t pllacount, uint32_t diva)
Enable PLLA clock.
Definition: pmc.c:409
uint32_t pmc_osc_is_ready_mainck(void)
Check if the MAINCK is ready. Depending on MOSCEL, MAINCK can be one of Xtal, bypass or internal RC...
Definition: pmc.c:397
uint32_t pmc_switch_pck_to_mainck(uint32_t ul_id, uint32_t ul_pres)
Switch programmable clock source selection to main clock.
Definition: pmc.c:696
void pmc_enable_sleepmode(uint8_t uc_type)
Enable Sleep Mode. Enter condition: (WFE or WFI) + (SLEEPDEEP bit = 0) + (LPM bit = 0) ...
Definition: pmc.c:972
void pmc_osc_disable_fastrc(void)
Disable the internal fast RC.
Definition: pmc.c:337
uint32_t pmc_switch_pck_to_pllack(uint32_t ul_id, uint32_t ul_pres)
Switch programmable clock source selection to PLLA clock.
Definition: pmc.c:720
void pmc_disable_pllack(void)
Disable PLLA clock.
Definition: pmc.c:422
void pmc_switch_mainck_to_fastrc(uint32_t ul_moscrcf)
Switch main clock source selection to internal fast RC.
Definition: pmc.c:290
uint32_t pmc_is_pck_enabled(uint32_t ul_id)
Check if the specified programmable clock is enabled.
Definition: pmc.c:833
void pmc_pck_set_prescaler(uint32_t ul_id, uint32_t ul_pres)
Set the prescaler for the specified programmable clock.
Definition: pmc.c:641
uint32_t pmc_switch_mck_to_mainck(uint32_t ul_pres)
Switch master clock source selection to main clock.
Definition: pmc.c:123
void pmc_mck_set_source(uint32_t ul_source)
Set the source of the MCK.
Definition: pmc.c:79
uint32_t pmc_get_status(void)
Get current status.
Definition: pmc.c:939
void pmc_pck_set_source(uint32_t ul_id, uint32_t ul_source)
Set the source oscillator for the specified programmable clock.
Definition: pmc.c:655
void pmc_set_writeprotect(uint32_t ul_enable)
Enable or disable write protect of PMC registers.
Definition: pmc.c:1020
void pmc_disable_pck(uint32_t ul_id)
Disable the specified programmable clock.
Definition: pmc.c:804
uint32_t pmc_disable_periph_clk(uint32_t ul_id)
Disable the specified peripheral clock.
Definition: pmc.c:550
void pmc_enable_backupmode(void)
Enable Backup Mode. Enter condition: WFE + (SLEEPDEEP bit = 1)
Definition: pmc.c:1009
uint32_t pmc_switch_mck_to_sclk(uint32_t ul_pres)
Switch master clock source selection to slow clock.
Definition: pmc.c:94
void pmc_disable_all_periph_clk(void)
Disable all peripheral clocks.
Definition: pmc.c:588
uint32_t pmc_switch_pck_to_sclk(uint32_t ul_id, uint32_t ul_pres)
Switch programmable clock source selection to slow clock.
Definition: pmc.c:672
void pmc_enable_pck(uint32_t ul_id)
Enable the specified programmable clock.
Definition: pmc.c:794
uint32_t pmc_is_locked_pllack(void)
Is PLLA locked?
Definition: pmc.c:433
uint32_t pmc_osc_is_ready_32kxtal(void)
Check if the external 32k Xtal is ready.
Definition: pmc.c:275