pm.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430
  1. /*!
  2. * Copyright (C) 2001-2010 by egnite Software GmbH
  3. *
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions
  8. * are met:
  9. *
  10. * 1. Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. * 2. Redistributions in binary form must reproduce the above copyright
  13. * notice, this list of conditions and the following disclaimer in the
  14. * documentation and/or other materials provided with the distribution.
  15. * 3. Neither the name of the copyright holders nor the names of
  16. * contributors may be used to endorse or promote products derived
  17. * from this software without specific prior written permission.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  20. * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  21. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  22. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  23. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  24. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  25. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  26. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  27. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  28. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
  29. * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  30. * SUCH DAMAGE.
  31. *
  32. * For additional information see http://www.ethernut.de/
  33. *
  34. * Portions Copyright Atmel Corporation, see the following note.
  35. */
  36. /* This header file is part of the ATMEL AVR-UC3-SoftwareFramework-1.7.0 Release */
  37. /*This file has been prepared for Doxygen automatic documentation generation.*/
  38. /*! \file *********************************************************************
  39. *
  40. * \brief Power Manager driver.
  41. *
  42. *
  43. * - Compiler: IAR EWAVR32 and GNU GCC for AVR32
  44. * - Supported devices: All AVR32 devices.
  45. * - AppNote:
  46. *
  47. * \author Atmel Corporation: http://www.atmel.com \n
  48. * Support and FAQ: http://support.atmel.no/
  49. *
  50. *****************************************************************************/
  51. /* Copyright (c) 2009 Atmel Corporation. All rights reserved.
  52. *
  53. * Redistribution and use in source and binary forms, with or without
  54. * modification, are permitted provided that the following conditions are met:
  55. *
  56. * 1. Redistributions of source code must retain the above copyright notice, this
  57. * list of conditions and the following disclaimer.
  58. *
  59. * 2. Redistributions in binary form must reproduce the above copyright notice,
  60. * this list of conditions and the following disclaimer in the documentation
  61. * and/or other materials provided with the distribution.
  62. *
  63. * 3. The name of Atmel may not be used to endorse or promote products derived
  64. * from this software without specific prior written permission.
  65. *
  66. * 4. This software may only be redistributed and used in connection with an Atmel
  67. * AVR product.
  68. *
  69. * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
  70. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  71. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
  72. * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
  73. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  74. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  75. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  76. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  77. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  78. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
  79. *
  80. */
  81. #ifndef _PM_H_
  82. #define _PM_H_
  83. #include <arch/avr32.h>
  84. #include <avr32/io.h>
  85. #include "preprocessor.h"
  86. /*! \brief Sets the MCU in the specified sleep mode.
  87. *
  88. * \param mode Sleep mode:
  89. * \arg \c AVR32_PM_SMODE_IDLE: Idle;
  90. * \arg \c AVR32_PM_SMODE_FROZEN: Frozen;
  91. * \arg \c AVR32_PM_SMODE_STANDBY: Standby;
  92. * \arg \c AVR32_PM_SMODE_STOP: Stop;
  93. * \arg \c AVR32_PM_SMODE_DEEP_STOP: DeepStop;
  94. * \arg \c AVR32_PM_SMODE_STATIC: Static.
  95. */
  96. #define SLEEP(mode) {__asm__ __volatile__ ("sleep "STRINGZ(mode));}
  97. /*!
  98. * \brief This function will enable the crystal mode of the oscillator 0.
  99. * \param pm Base address of the Power Manager (i.e. &AVR32_PM)
  100. * \param fosc0 Oscillator 0 crystal frequency (Hz)
  101. */
  102. extern void pm_enable_osc0_crystal(unsigned int fosc0);
  103. /*!
  104. * \brief This function will enable the oscillator 0 to be used with a startup time.
  105. * \param pm Base address of the Power Manager (i.e. &AVR32_PM)
  106. * \param startup Clock 0 startup time. AVR32_PM_OSCCTRL0_STARTUP_x_RCOSC.
  107. */
  108. extern void pm_enable_clk0(unsigned int startup);
  109. /*!
  110. * \brief This function will disable the oscillator 0.
  111. * \param pm Base address of the Power Manager (i.e. &AVR32_PM)
  112. */
  113. extern void pm_disable_clk0(volatile avr32_pm_t *pm);
  114. /*!
  115. * \brief This function will enable the oscillator 0 to be used with no startup time.
  116. * \param pm Base address of the Power Manager (i.e. &AVR32_PM)
  117. * \param startup Clock 0 startup time, for which the function does not wait. AVR32_PM_OSCCTRL0_STARTUP_x_RCOSC.
  118. */
  119. extern void pm_enable_clk0_no_wait(volatile avr32_pm_t *pm, unsigned int startup);
  120. /*!
  121. * \brief This function will wait until the Osc0 clock is ready.
  122. * \param pm Base address of the Power Manager (i.e. &AVR32_PM)
  123. */
  124. extern void pm_wait_for_clk0_ready(volatile avr32_pm_t *pm);
  125. /*!
  126. * \brief This function will enable the external clock mode of the oscillator 1.
  127. * \param pm Base address of the Power Manager (i.e. &AVR32_PM)
  128. */
  129. extern void pm_enable_osc1_ext_clock(volatile avr32_pm_t *pm);
  130. /*!
  131. * \brief This function will enable the crystal mode of the oscillator 1.
  132. * \param pm Base address of the Power Manager (i.e. &AVR32_PM)
  133. * \param fosc1 Oscillator 1 crystal frequency (Hz)
  134. */
  135. extern void pm_enable_osc1_crystal(volatile avr32_pm_t *pm, unsigned int fosc1);
  136. /*!
  137. * \brief This function will enable the oscillator 1 to be used with a startup time.
  138. * \param pm Base address of the Power Manager (i.e. &AVR32_PM)
  139. * \param startup Clock 1 startup time. AVR32_PM_OSCCTRL1_STARTUP_x_RCOSC.
  140. */
  141. extern void pm_enable_clk1(volatile avr32_pm_t *pm, unsigned int startup);
  142. /*!
  143. * \brief This function will disable the oscillator 1.
  144. * \param pm Base address of the Power Manager (i.e. &AVR32_PM)
  145. */
  146. extern void pm_disable_clk1(volatile avr32_pm_t *pm);
  147. /*!
  148. * \brief This function will enable the oscillator 1 to be used with no startup time.
  149. * \param pm Base address of the Power Manager (i.e. &AVR32_PM)
  150. * \param startup Clock 1 startup time, for which the function does not wait. AVR32_PM_OSCCTRL1_STARTUP_x_RCOSC.
  151. */
  152. extern void pm_enable_clk1_no_wait(volatile avr32_pm_t *pm, unsigned int startup);
  153. /*!
  154. * \brief This function will wait until the Osc1 clock is ready.
  155. * \param pm Base address of the Power Manager (i.e. &AVR32_PM)
  156. */
  157. extern void pm_wait_for_clk1_ready(volatile avr32_pm_t *pm);
  158. /*!
  159. * \brief This function will enable the external clock mode of the 32-kHz oscillator.
  160. * \param pm Base address of the Power Manager (i.e. &AVR32_PM)
  161. */
  162. extern void pm_enable_osc32_ext_clock(volatile avr32_pm_t *pm);
  163. /*!
  164. * \brief This function will enable the crystal mode of the 32-kHz oscillator.
  165. * \param pm Base address of the Power Manager (i.e. &AVR32_PM)
  166. */
  167. extern void pm_enable_osc32_crystal(volatile avr32_pm_t *pm);
  168. /*!
  169. * \brief This function will enable the oscillator 32 to be used with a startup time.
  170. * \param pm Base address of the Power Manager (i.e. &AVR32_PM)
  171. * \param startup Clock 32 kHz startup time. AVR32_PM_OSCCTRL32_STARTUP_x_RCOSC.
  172. */
  173. extern void pm_enable_clk32(volatile avr32_pm_t *pm, unsigned int startup);
  174. /*!
  175. * \brief This function will disable the oscillator 32.
  176. * \param pm Base address of the Power Manager (i.e. &AVR32_PM)
  177. */
  178. extern void pm_disable_clk32(volatile avr32_pm_t *pm);
  179. /*!
  180. * \brief This function will enable the oscillator 32 to be used with no startup time.
  181. * \param pm Base address of the Power Manager (i.e. &AVR32_PM)
  182. * \param startup Clock 32 kHz startup time, for which the function does not wait. AVR32_PM_OSCCTRL32_STARTUP_x_RCOSC.
  183. */
  184. extern void pm_enable_clk32_no_wait(volatile avr32_pm_t *pm, unsigned int startup);
  185. /*!
  186. * \brief This function will wait until the osc32 clock is ready.
  187. * \param pm Base address of the Power Manager (i.e. &AVR32_PM)
  188. */
  189. extern void pm_wait_for_clk32_ready(volatile avr32_pm_t *pm);
  190. /*!
  191. * \brief This function will select all the power manager clocks.
  192. * \param pm Base address of the Power Manager (i.e. &AVR32_PM)
  193. * \param pbadiv Peripheral Bus A clock divisor enable
  194. * \param pbasel Peripheral Bus A select
  195. * \param pbbdiv Peripheral Bus B clock divisor enable
  196. * \param pbbsel Peripheral Bus B select
  197. * \param hsbdiv High Speed Bus clock divisor enable (CPU clock = HSB clock)
  198. * \param hsbsel High Speed Bus select (CPU clock = HSB clock )
  199. */
  200. extern void pm_cksel(volatile avr32_pm_t *pm, unsigned int pbadiv, unsigned int pbasel, unsigned int pbbdiv, unsigned int pbbsel, unsigned int hsbdiv, unsigned int hsbsel);
  201. /*!
  202. * \brief This function will setup a PLL.
  203. * \param pm Base address of the Power Manager (i.e. &AVR32_PM)
  204. * \param pll PLL number(0 for PLL0, 1 for PLL1)
  205. * \param mul PLL MUL in the PLL formula
  206. * \param div PLL DIV in the PLL formula
  207. * \param osc OSC number (0 for osc0, 1 for osc1)
  208. * \param lockcount PLL lockount
  209. */
  210. extern void pm_pll_setup(volatile avr32_pm_t *pm, unsigned int pll, unsigned int mul, unsigned int div, unsigned int osc, unsigned int lockcount);
  211. /*!
  212. * \brief This function will set a PLL option.
  213. * \param pm Base address of the Power Manager (i.e. &AVR32_PM)
  214. * \param pll PLL number(0 for PLL0, 1 for PLL1)
  215. * \param pll_freq Set to 1 for VCO frequency range 80-180MHz, set to 0 for VCO frequency range 160-240Mhz.
  216. * \param pll_div2 Divide the PLL output frequency by 2 (this settings does not change the FVCO value)
  217. * \param pll_wbwdisable 1 Disable the Wide-Bandith Mode (Wide-Bandwith mode allow a faster startup time and out-of-lock time). 0 to enable the Wide-Bandith Mode.
  218. */
  219. extern void pm_pll_set_option(volatile avr32_pm_t *pm, unsigned int pll, unsigned int pll_freq, unsigned int pll_div2, unsigned int pll_wbwdisable);
  220. /*!
  221. * \brief This function will get a PLL option.
  222. * \param pm Base address of the Power Manager (i.e. &AVR32_PM)
  223. * \param pll PLL number(0 for PLL0, 1 for PLL1)
  224. * \return Option
  225. */
  226. extern unsigned int pm_pll_get_option(volatile avr32_pm_t *pm, unsigned int pll);
  227. /*!
  228. * \brief This function will enable a PLL.
  229. * \param pm Base address of the Power Manager (i.e. &AVR32_PM)
  230. * \param pll PLL number(0 for PLL0, 1 for PLL1)
  231. */
  232. extern void pm_pll_enable(volatile avr32_pm_t *pm, unsigned int pll);
  233. /*!
  234. * \brief This function will disable a PLL.
  235. * \param pm Base address of the Power Manager (i.e. &AVR32_PM)
  236. * \param pll PLL number(0 for PLL0, 1 for PLL1)
  237. */
  238. extern void pm_pll_disable(volatile avr32_pm_t *pm, unsigned int pll);
  239. /*!
  240. * \brief This function will wait for PLL0 locked
  241. * \param pm Base address of the Power Manager (i.e. &AVR32_PM)
  242. */
  243. extern void pm_wait_for_pll0_locked(volatile avr32_pm_t *pm);
  244. /*!
  245. * \brief This function will wait for PLL1 locked
  246. * \param pm Base address of the Power Manager (i.e. &AVR32_PM)
  247. */
  248. extern void pm_wait_for_pll1_locked(volatile avr32_pm_t *pm);
  249. /*!
  250. * \brief This function will switch the power manager main clock.
  251. * \param pm Base address of the Power Manager (i.e. &AVR32_PM)
  252. * \param clock Clock to be switched on. AVR32_PM_MCSEL_SLOW for RCOsc, AVR32_PM_MCSEL_OSC0 for Osc0, AVR32_PM_MCSEL_PLL0 for PLL0.
  253. */
  254. extern void pm_switch_to_clock(unsigned long clock);
  255. /*!
  256. * \brief Switch main clock to clock Osc0 (crystal mode)
  257. * \param pm Base address of the Power Manager (i.e. &AVR32_PM)
  258. * \param fosc0 Oscillator 0 crystal frequency (Hz)
  259. * \param startup Crystal 0 startup time. AVR32_PM_OSCCTRL0_STARTUP_x_RCOSC.
  260. */
  261. extern void pm_switch_to_osc0(unsigned int fosc0, unsigned int startup);
  262. /*! \brief Enables the Brown-Out Detector interrupt.
  263. *
  264. * \param pm Base address of the Power Manager (i.e. &AVR32_PM).
  265. */
  266. extern void pm_bod_enable_irq(volatile avr32_pm_t *pm);
  267. /*! \brief Disables the Brown-Out Detector interrupt.
  268. *
  269. * \param pm Base address of the Power Manager (i.e. &AVR32_PM).
  270. */
  271. extern void pm_bod_disable_irq(volatile avr32_pm_t *pm);
  272. /*! \brief Clears the Brown-Out Detector interrupt flag.
  273. *
  274. * \param pm Base address of the Power Manager (i.e. &AVR32_PM).
  275. */
  276. extern void pm_bod_clear_irq(volatile avr32_pm_t *pm);
  277. /*! \brief Gets the Brown-Out Detector interrupt flag.
  278. *
  279. * \param pm Base address of the Power Manager (i.e. &AVR32_PM).
  280. *
  281. * \retval 0 No BOD interrupt.
  282. * \retval 1 BOD interrupt pending.
  283. */
  284. extern unsigned long pm_bod_get_irq_status(volatile avr32_pm_t *pm);
  285. /*! \brief Gets the Brown-Out Detector interrupt enable status.
  286. *
  287. * \param pm Base address of the Power Manager (i.e. &AVR32_PM).
  288. *
  289. * \retval 0 BOD interrupt disabled.
  290. * \retval 1 BOD interrupt enabled.
  291. */
  292. extern unsigned long pm_bod_get_irq_enable_bit(volatile avr32_pm_t *pm);
  293. /*! \brief Gets the triggering threshold of the Brown-Out Detector.
  294. *
  295. * \param pm Base address of the Power Manager (i.e. &AVR32_PM).
  296. *
  297. * \return Triggering threshold of the BOD. See the electrical characteristics
  298. * in the part datasheet for actual voltage levels.
  299. */
  300. extern unsigned long pm_bod_get_level(volatile avr32_pm_t *pm);
  301. /*!
  302. * \brief Read the content of the PM GPLP registers
  303. * \param pm Base address of the Power Manager (i.e. &AVR32_PM)
  304. * \param gplp GPLP register index (0,1,... depending on the number of GPLP registers for a given part)
  305. *
  306. * \return The content of the chosen GPLP register.
  307. */
  308. extern unsigned long pm_read_gplp(volatile avr32_pm_t *pm, unsigned long gplp);
  309. /*!
  310. * \brief Write into the PM GPLP registers
  311. * \param pm Base address of the Power Manager (i.e. &AVR32_PM)
  312. * \param gplp GPLP register index (0,1,... depending on the number of GPLP registers for a given part)
  313. * \param value Value to write
  314. */
  315. extern void pm_write_gplp(volatile avr32_pm_t *pm, unsigned long gplp, unsigned long value);
  316. /*! \brief Enable the clock of a module.
  317. *
  318. * \param pm Base address of the Power Manager (i.e. &AVR32_PM)
  319. * \param module The module to clock (use one of the defines in the part-specific
  320. * header file under "toolchain folder"/avr32/inc(lude)/avr32/; depending on the
  321. * clock domain, look for the sections "CPU clocks", "HSB clocks", "PBx clocks")
  322. *
  323. * \return Status.
  324. * \retval 0 Success.
  325. * \retval <0 An error occured.
  326. */
  327. extern long pm_enable_module(volatile avr32_pm_t *pm, unsigned long module);
  328. /*! \brief Disable the clock of a module.
  329. *
  330. * \param pm Base address of the Power Manager (i.e. &AVR32_PM)
  331. * \param module The module to shut down (use one of the defines in the part-specific
  332. * header file under "toolchain folder"/avr32/inc(lude)/avr32/; depending on the
  333. * clock domain, look for the sections "CPU clocks", "HSB clocks", "PBx clocks")
  334. *
  335. * \return Status.
  336. * \retval 0 Success.
  337. * \retval <0 An error occured.
  338. */
  339. extern long pm_disable_module(volatile avr32_pm_t *pm, unsigned long module);
  340. /*! \brief Automatically configure the USB clock.
  341. *
  342. * USB clock is configured to 48MHz, using the PLL1 from the Oscillator0, assuming
  343. * a 12 MHz crystal is connected to it.
  344. */
  345. extern void pm_configure_usb_clock(void);
  346. extern void Avr32InitClockTree(void);
  347. #endif // _PM_H_