1 |
608 |
jeremybenn |
/* ----------------------------------------------------------------------------
|
2 |
|
|
* ATMEL Microcontroller Software Support
|
3 |
|
|
* ----------------------------------------------------------------------------
|
4 |
|
|
* Copyright (c) 2008, 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 conditions are 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 |
|
|
|
30 |
|
|
//------------------------------------------------------------------------------
|
31 |
|
|
// Headers
|
32 |
|
|
//------------------------------------------------------------------------------
|
33 |
|
|
|
34 |
|
|
#include "pmc.h"
|
35 |
|
|
#include <board.h>
|
36 |
|
|
#include <utility/assert.h>
|
37 |
|
|
#include <utility/trace.h>
|
38 |
|
|
|
39 |
|
|
//------------------------------------------------------------------------------
|
40 |
|
|
// Global functions
|
41 |
|
|
//------------------------------------------------------------------------------
|
42 |
|
|
|
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)
|
49 |
|
|
{
|
50 |
|
|
SANITY_CHECK((inputs & ~0xFF) == 0);
|
51 |
|
|
AT91C_BASE_PMC->PMC_FSMR = inputs;
|
52 |
|
|
}
|
53 |
|
|
|
54 |
|
|
#if !defined(__ICCARM__)
|
55 |
|
|
__attribute__ ((section (".ramfunc"))) // GCC
|
56 |
|
|
#endif
|
57 |
|
|
//------------------------------------------------------------------------------
|
58 |
|
|
/// Disables the main oscillator, making the device enter Wait mode.
|
59 |
|
|
//------------------------------------------------------------------------------
|
60 |
|
|
void PMC_DisableMainOscillatorForWaitMode(void)
|
61 |
|
|
{
|
62 |
|
|
AT91C_BASE_PMC->PMC_MOR = 0x37 << 16;
|
63 |
|
|
while ((AT91C_BASE_PMC->PMC_MOR & AT91C_PMC_MAINSELS) != AT91C_PMC_MAINSELS);
|
64 |
|
|
}
|
65 |
|
|
|
66 |
|
|
#endif
|
67 |
|
|
|
68 |
|
|
#if defined(at91sam7l)
|
69 |
|
|
//------------------------------------------------------------------------------
|
70 |
|
|
/// Disables the main oscillator when NOT running on it.
|
71 |
|
|
//------------------------------------------------------------------------------
|
72 |
|
|
void PMC_DisableMainOscillator(void)
|
73 |
|
|
{
|
74 |
|
|
AT91C_BASE_PMC->PMC_MOR = 0x37 << 16;
|
75 |
|
|
while ((AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MAINSELS) == AT91C_PMC_MAINSELS);
|
76 |
|
|
}
|
77 |
|
|
#endif
|
78 |
|
|
|
79 |
|
|
//------------------------------------------------------------------------------
|
80 |
|
|
/// Disables the processor clock, making the device enter Idle mode.
|
81 |
|
|
//------------------------------------------------------------------------------
|
82 |
|
|
void PMC_DisableProcessorClock(void)
|
83 |
|
|
{
|
84 |
|
|
AT91C_BASE_PMC->PMC_SCDR = AT91C_PMC_PCK;
|
85 |
|
|
while ((AT91C_BASE_PMC->PMC_SCSR & AT91C_PMC_PCK) != AT91C_PMC_PCK);
|
86 |
|
|
}
|
87 |
|
|
|
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)
|
95 |
|
|
{
|
96 |
|
|
SANITY_CHECK(id < 32);
|
97 |
|
|
|
98 |
|
|
if ((AT91C_BASE_PMC->PMC_PCSR & (1 << id)) == (1 << id)) {
|
99 |
|
|
|
100 |
|
|
trace_LOG(trace_INFO,
|
101 |
|
|
"-I- PMC_EnablePeripheral: clock of peripheral"
|
102 |
|
|
" %u is already enabled\n\r",
|
103 |
|
|
id);
|
104 |
|
|
}
|
105 |
|
|
else {
|
106 |
|
|
|
107 |
|
|
AT91C_BASE_PMC->PMC_PCER = 1 << id;
|
108 |
|
|
}
|
109 |
|
|
}
|
110 |
|
|
|
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)
|
118 |
|
|
{
|
119 |
|
|
SANITY_CHECK(id < 32);
|
120 |
|
|
|
121 |
|
|
if ((AT91C_BASE_PMC->PMC_PCSR & (1 << id)) != (1 << id)) {
|
122 |
|
|
|
123 |
|
|
trace_LOG(trace_INFO,
|
124 |
|
|
"-I- PMC_DisablePeripheral: clock of peripheral"
|
125 |
|
|
" %u is not enabled\n\r",
|
126 |
|
|
id);
|
127 |
|
|
}
|
128 |
|
|
else {
|
129 |
|
|
|
130 |
|
|
AT91C_BASE_PMC->PMC_PCDR = 1 << id;
|
131 |
|
|
}
|
132 |
|
|
}
|
133 |
|
|
|