1 /* ----------------------------------------------------------------------------
\r
2 * ATMEL Microcontroller Software Support
\r
3 * ----------------------------------------------------------------------------
\r
4 * Copyright (c) 2008, Atmel Corporation
\r
6 * All rights reserved.
\r
8 * Redistribution and use in source and binary forms, with or without
\r
9 * modification, are permitted provided that the following conditions are met:
\r
11 * - Redistributions of source code must retain the above copyright notice,
\r
12 * this list of conditions and the disclaimer below.
\r
14 * Atmel's name may not be used to endorse or promote products derived from
\r
15 * this software without specific prior written permission.
\r
17 * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
\r
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
\r
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
\r
20 * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
\r
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
\r
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
\r
23 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
\r
24 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
\r
25 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
\r
26 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\r
27 * ----------------------------------------------------------------------------
\r
30 //------------------------------------------------------------------------------
\r
32 //------------------------------------------------------------------------------
\r
36 #include <utility/assert.h>
\r
37 #include <utility/trace.h>
\r
39 //------------------------------------------------------------------------------
\r
41 //------------------------------------------------------------------------------
\r
43 #if defined(at91sam7l64) || defined(at91sam7l128)
\r
44 //------------------------------------------------------------------------------
\r
45 /// Sets the fast wake-up inputs that can get the device out of Wait mode.
\r
46 /// \param inputs Fast wake-up inputs to enable.
\r
47 //------------------------------------------------------------------------------
\r
48 void PMC_SetFastWakeUpInputs(unsigned int inputs)
\r
50 SANITY_CHECK((inputs & ~0xFF) == 0);
\r
51 AT91C_BASE_PMC->PMC_FSMR = inputs;
\r
54 #if !defined(__ICCARM__)
\r
55 __attribute__ ((section (".ramfunc"))) // GCC
\r
57 //------------------------------------------------------------------------------
\r
58 /// Disables the main oscillator, making the device enter Wait mode.
\r
59 //------------------------------------------------------------------------------
\r
60 void PMC_DisableMainOscillatorForWaitMode(void)
\r
62 AT91C_BASE_PMC->PMC_MOR = 0x37 << 16;
\r
63 while ((AT91C_BASE_PMC->PMC_MOR & AT91C_PMC_MAINSELS) != AT91C_PMC_MAINSELS);
\r
68 #if defined(at91sam7l)
\r
69 //------------------------------------------------------------------------------
\r
70 /// Disables the main oscillator when NOT running on it.
\r
71 //------------------------------------------------------------------------------
\r
72 void PMC_DisableMainOscillator(void)
\r
74 AT91C_BASE_PMC->PMC_MOR = 0x37 << 16;
\r
75 while ((AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MAINSELS) == AT91C_PMC_MAINSELS);
\r
79 //------------------------------------------------------------------------------
\r
80 /// Disables the processor clock, making the device enter Idle mode.
\r
81 //------------------------------------------------------------------------------
\r
82 void PMC_DisableProcessorClock(void)
\r
84 AT91C_BASE_PMC->PMC_SCDR = AT91C_PMC_PCK;
\r
85 while ((AT91C_BASE_PMC->PMC_SCSR & AT91C_PMC_PCK) != AT91C_PMC_PCK);
\r
88 //------------------------------------------------------------------------------
\r
89 /// Enables the clock of a peripheral. The peripheral ID (AT91C_ID_xxx) is used
\r
90 /// to identify which peripheral is targetted.
\r
91 /// Note that the ID must NOT be shifted (i.e. 1 << AT91C_ID_xxx).
\r
92 /// \param id Peripheral ID (AT91C_ID_xxx).
\r
93 //------------------------------------------------------------------------------
\r
94 void PMC_EnablePeripheral(unsigned int id)
\r
96 SANITY_CHECK(id < 32);
\r
98 if ((AT91C_BASE_PMC->PMC_PCSR & (1 << id)) == (1 << id)) {
\r
100 trace_LOG(trace_INFO,
\r
101 "-I- PMC_EnablePeripheral: clock of peripheral"
\r
102 " %u is already enabled\n\r",
\r
107 AT91C_BASE_PMC->PMC_PCER = 1 << id;
\r
111 //------------------------------------------------------------------------------
\r
112 /// Disables the clock of a peripheral. The peripheral ID (AT91C_ID_xxx) is used
\r
113 /// to identify which peripheral is targetted.
\r
114 /// Note that the ID must NOT be shifted (i.e. 1 << AT91C_ID_xxx).
\r
115 /// \param id Peripheral ID (AT91C_ID_xxx).
\r
116 //------------------------------------------------------------------------------
\r
117 void PMC_DisablePeripheral(unsigned int id)
\r
119 SANITY_CHECK(id < 32);
\r
121 if ((AT91C_BASE_PMC->PMC_PCSR & (1 << id)) != (1 << id)) {
\r
123 trace_LOG(trace_INFO,
\r
124 "-I- PMC_DisablePeripheral: clock of peripheral"
\r
125 " %u is not enabled\n\r",
\r
130 AT91C_BASE_PMC->PMC_PCDR = 1 << id;
\r