1 /* ----------------------------------------------------------------------------
2 * ATMEL Microcontroller Software Support
3 * ----------------------------------------------------------------------------
4 * Copyright (c) 2008, Atmel Corporation
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are met:
11 * - Redistributions of source code must retain the above copyright notice,
12 * this list of conditions and the disclaimer below.
14 * Atmel's name may not be used to endorse or promote products derived from
15 * this software without specific prior written permission.
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 * ----------------------------------------------------------------------------
30 //------------------------------------------------------------------------------
32 //------------------------------------------------------------------------------
36 #include <utility/assert.h>
37 #include <utility/trace.h>
39 //------------------------------------------------------------------------------
41 //------------------------------------------------------------------------------
43 #if defined(at91sam7l64) || defined(at91sam7l128)
44 //------------------------------------------------------------------------------
45 /// Sets the fast wake-up inputs that can get the device out of Wait mode.
46 /// \param inputs Fast wake-up inputs to enable.
47 //------------------------------------------------------------------------------
48 void PMC_SetFastWakeUpInputs(unsigned int inputs)
50 SANITY_CHECK((inputs & ~0xFF) == 0);
51 AT91C_BASE_PMC->PMC_FSMR = inputs;
54 #if !defined(__ICCARM__)
55 __attribute__ ((section (".ramfunc"))) // GCC
57 //------------------------------------------------------------------------------
58 /// Disables the main oscillator, making the device enter Wait mode.
59 //------------------------------------------------------------------------------
60 void PMC_DisableMainOscillatorForWaitMode(void)
62 AT91C_BASE_PMC->PMC_MOR = 0x37 << 16;
63 while ((AT91C_BASE_PMC->PMC_MOR & AT91C_PMC_MAINSELS) != AT91C_PMC_MAINSELS);
68 #if defined(at91sam7l)
69 //------------------------------------------------------------------------------
70 /// Disables the main oscillator when NOT running on it.
71 //------------------------------------------------------------------------------
72 void PMC_DisableMainOscillator(void)
74 AT91C_BASE_PMC->PMC_MOR = 0x37 << 16;
75 while ((AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MAINSELS) == AT91C_PMC_MAINSELS);
79 //------------------------------------------------------------------------------
80 /// Disables the processor clock, making the device enter Idle mode.
81 //------------------------------------------------------------------------------
82 void PMC_DisableProcessorClock(void)
84 AT91C_BASE_PMC->PMC_SCDR = AT91C_PMC_PCK;
85 while ((AT91C_BASE_PMC->PMC_SCSR & AT91C_PMC_PCK) != AT91C_PMC_PCK);
88 //------------------------------------------------------------------------------
89 /// Enables the clock of a peripheral. The peripheral ID (AT91C_ID_xxx) is used
90 /// to identify which peripheral is targetted.
91 /// Note that the ID must NOT be shifted (i.e. 1 << AT91C_ID_xxx).
92 /// \param id Peripheral ID (AT91C_ID_xxx).
93 //------------------------------------------------------------------------------
94 void PMC_EnablePeripheral(unsigned int id)
96 SANITY_CHECK(id < 32);
98 if ((AT91C_BASE_PMC->PMC_PCSR & (1 << id)) == (1 << id)) {
100 trace_LOG(trace_INFO,
101 "-I- PMC_EnablePeripheral: clock of peripheral"
102 " %u is already enabled\n\r",
107 AT91C_BASE_PMC->PMC_PCER = 1 << id;
111 //------------------------------------------------------------------------------
112 /// Disables the clock of a peripheral. The peripheral ID (AT91C_ID_xxx) is used
113 /// to identify which peripheral is targetted.
114 /// Note that the ID must NOT be shifted (i.e. 1 << AT91C_ID_xxx).
115 /// \param id Peripheral ID (AT91C_ID_xxx).
116 //------------------------------------------------------------------------------
117 void PMC_DisablePeripheral(unsigned int id)
119 SANITY_CHECK(id < 32);
121 if ((AT91C_BASE_PMC->PMC_PCSR & (1 << id)) != (1 << id)) {
123 trace_LOG(trace_INFO,
124 "-I- PMC_DisablePeripheral: clock of peripheral"
125 " %u is not enabled\n\r",
130 AT91C_BASE_PMC->PMC_PCDR = 1 << id;