OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [freertos-6.1.1/] [Demo/] [Common/] [drivers/] [Atmel/] [at91lib/] [peripherals/] [supc/] [supc.c] - Blame information for rev 608

Details | Compare with Previous | View Log

Line No. Rev Author Line
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 "supc.h"
35
#include <board.h>
36
#include <utility/assert.h>
37
 
38
//------------------------------------------------------------------------------
39
//         Local definitions
40
//------------------------------------------------------------------------------
41
 
42
/// Key value for the SUPC_MR register.
43
#define SUPC_KEY            ((unsigned int) (0xA5 << 24))
44
 
45
//------------------------------------------------------------------------------
46
//         Global functions
47
//------------------------------------------------------------------------------
48
 
49
//------------------------------------------------------------------------------
50
/// Enables the SLCD power supply.
51
/// \param internal  If 1, the power supply is configured as internal; otherwise
52
///                  it is set at external.
53
//------------------------------------------------------------------------------
54
void SUPC_EnableSlcd(unsigned char internal)
55
{
56
    if (internal) {
57
 
58
         AT91C_BASE_SUPC->SUPC_MR = SUPC_KEY | (AT91C_BASE_SUPC->SUPC_MR & ~AT91C_SUPC_LCDMODE) | AT91C_SUPC_LCDMODE_INTERNAL;
59
    }
60
    else {
61
 
62
        AT91C_BASE_SUPC->SUPC_MR = SUPC_KEY | (AT91C_BASE_SUPC->SUPC_MR & ~AT91C_SUPC_LCDMODE) | AT91C_SUPC_LCDMODE_EXTERNAL;
63
    }
64
    while ((AT91C_BASE_SUPC->SUPC_SR & AT91C_SUPC_LCDS) != AT91C_SUPC_LCDS);
65
}
66
 
67
//------------------------------------------------------------------------------
68
/// Disables the SLCD power supply.
69
//------------------------------------------------------------------------------
70
void SUPC_DisableSlcd(void)
71
{
72
    AT91C_BASE_SUPC->SUPC_MR = SUPC_KEY | (AT91C_BASE_SUPC->SUPC_MR & ~AT91C_SUPC_LCDMODE);
73
    while ((AT91C_BASE_SUPC->SUPC_SR & AT91C_SUPC_LCDS) == AT91C_SUPC_LCDS);
74
}
75
 
76
//------------------------------------------------------------------------------
77
/// Sets the output voltage of the SLCD charge pump.
78
/// \param voltage  Output voltage.
79
//------------------------------------------------------------------------------
80
void SUPC_SetSlcdVoltage(unsigned int voltage)
81
{
82
    SANITY_CHECK((voltage & ~AT91C_SUPC_LCDOUT) == 0);
83
    AT91C_BASE_SUPC->SUPC_MR = SUPC_KEY | (AT91C_BASE_SUPC->SUPC_MR & ~AT91C_SUPC_LCDOUT) | voltage;
84
}
85
 
86
#if !defined(__ICCARM__)
87
__attribute__ ((section (".ramfunc"))) // GCC
88
#endif
89
//------------------------------------------------------------------------------
90
/// Enables the flash power supply with the given wake-up setting.
91
/// \param time  Wake-up time.
92
//------------------------------------------------------------------------------
93
void SUPC_EnableFlash(unsigned int time)
94
{
95
    AT91C_BASE_SUPC->SUPC_FWUTR = time;
96
    AT91C_BASE_SUPC->SUPC_MR = SUPC_KEY | AT91C_BASE_SUPC->SUPC_MR | AT91C_SUPC_FLASHON;
97
    while ((AT91C_BASE_SUPC->SUPC_SR & AT91C_SUPC_FLASHS) != AT91C_SUPC_FLASHS);
98
}
99
 
100
#if !defined(__ICCARM__)
101
__attribute__ ((section (".ramfunc"))) // GCC
102
#endif
103
//------------------------------------------------------------------------------
104
/// Disables the flash power supply.
105
//------------------------------------------------------------------------------
106
void SUPC_DisableFlash(void)
107
{
108
    AT91C_BASE_SUPC->SUPC_MR = SUPC_KEY | (AT91C_BASE_SUPC->SUPC_MR & ~AT91C_SUPC_FLASHON);
109
    while ((AT91C_BASE_SUPC->SUPC_SR & AT91C_SUPC_FLASHS) == AT91C_SUPC_FLASHS);
110
}
111
 
112
//------------------------------------------------------------------------------
113
/// Sets the voltage regulator output voltage.
114
/// \param voltage  Voltage to set.
115
//------------------------------------------------------------------------------
116
void SUPC_SetVoltageOutput(unsigned int voltage)
117
{
118
    SANITY_CHECK((voltage & ~AT91C_SUPC_VRVDD) == 0);
119
    AT91C_BASE_SUPC->SUPC_MR = SUPC_KEY | (AT91C_BASE_SUPC->SUPC_MR & ~AT91C_SUPC_VRVDD) | voltage;
120
}
121
 
122
//------------------------------------------------------------------------------
123
/// Puts the voltage regulator in deep mode.
124
//------------------------------------------------------------------------------
125
void SUPC_EnableDeepMode(void)
126
{
127
    AT91C_BASE_SUPC->SUPC_MR = SUPC_KEY | AT91C_BASE_SUPC->SUPC_MR | AT91C_SUPC_VRDEEP;
128
}
129
 
130
//------------------------------------------------------------------------------
131
/// Puts the voltage regulator in normal mode.
132
//------------------------------------------------------------------------------
133
void SUPC_DisableDeepMode(void)
134
{
135
    AT91C_BASE_SUPC->SUPC_MR = SUPC_KEY | (AT91C_BASE_SUPC->SUPC_MR & ~AT91C_SUPC_VRDEEP);
136
}
137
 
138
//-----------------------------------------------------------------------------
139
/// Enables the backup SRAM power supply, so its data is saved while the device
140
/// is in backup mode.
141
//-----------------------------------------------------------------------------
142
void SUPC_EnableSram(void)
143
{
144
    AT91C_BASE_SUPC->SUPC_MR = SUPC_KEY | AT91C_BASE_SUPC->SUPC_MR | AT91C_SUPC_SRAMON;
145
}
146
 
147
//-----------------------------------------------------------------------------
148
/// Disables the backup SRAM power supply.
149
//-----------------------------------------------------------------------------
150
void SUPC_DisableSram(void)
151
{
152
    AT91C_BASE_SUPC->SUPC_MR = SUPC_KEY | (AT91C_BASE_SUPC->SUPC_MR & ~AT91C_SUPC_SRAMON);
153
}
154
 
155
//-----------------------------------------------------------------------------
156
/// Enables the RTC power supply.
157
//-----------------------------------------------------------------------------
158
void SUPC_EnableRtc(void)
159
{
160
    AT91C_BASE_SUPC->SUPC_MR = SUPC_KEY | AT91C_BASE_SUPC->SUPC_MR | AT91C_SUPC_RTCON;
161
    while ((AT91C_BASE_SUPC->SUPC_SR & AT91C_SUPC_RTS) != AT91C_SUPC_RTS);
162
}
163
 
164
//-----------------------------------------------------------------------------
165
/// Disables the RTC power supply.
166
//-----------------------------------------------------------------------------
167
void SUPC_DisableRtc(void)
168
{
169
    AT91C_BASE_SUPC->SUPC_MR = SUPC_KEY | (AT91C_BASE_SUPC->SUPC_MR & ~AT91C_SUPC_RTCON);
170
    while ((AT91C_BASE_SUPC->SUPC_SR & AT91C_SUPC_RTS) == AT91C_SUPC_RTS);
171
}
172
 
173
//-----------------------------------------------------------------------------
174
/// Sets the BOD sampling mode (or disables it).
175
/// \param mode  BOD sampling mode.
176
//-----------------------------------------------------------------------------
177
void SUPC_SetBodSampling(unsigned int mode)
178
{
179
    SANITY_CHECK((mode & ~AT91C_SUPC_BODSMPL) == 0);
180
    AT91C_BASE_SUPC->SUPC_BOMR &= ~AT91C_SUPC_BODSMPL;
181
    AT91C_BASE_SUPC->SUPC_BOMR |= mode;
182
}
183
 
184
//------------------------------------------------------------------------------
185
/// Disables the voltage regulator, which makes the device enter backup mode.
186
//------------------------------------------------------------------------------
187
void SUPC_DisableVoltageRegulator(void)
188
{
189
    AT91C_BASE_SUPC->SUPC_CR = SUPC_KEY | AT91C_SUPC_VROFF;
190
    while (1);
191
}
192
 
193
//------------------------------------------------------------------------------
194
/// Shuts the device down so it enters Off mode.
195
//------------------------------------------------------------------------------
196
void SUPC_Shutdown(void)
197
{
198
    AT91C_BASE_SUPC->SUPC_CR = SUPC_KEY | AT91C_SUPC_SHDW;
199
    while (1);
200
}
201
 
202
//------------------------------------------------------------------------------
203
/// Sets the wake-up sources when in backup mode.
204
/// \param sources  Wake-up sources to enable.
205
//------------------------------------------------------------------------------
206
void SUPC_SetWakeUpSources(unsigned int sources)
207
{
208
    SANITY_CHECK((sources & ~0x0000000B) == 0);
209
    AT91C_BASE_SUPC->SUPC_WUMR &= ~0x0000000B;
210
    AT91C_BASE_SUPC->SUPC_WUMR |= sources;
211
}
212
 
213
//------------------------------------------------------------------------------
214
/// Sets the wake-up inputs when in backup mode.
215
/// \param inputs  Wake up inputs to enable.
216
//------------------------------------------------------------------------------
217
void SUPC_SetWakeUpInputs(unsigned int inputs)
218
{
219
    SANITY_CHECK((inputs & ~0xFFFF) == 0);
220
    AT91C_BASE_SUPC->SUPC_WUIR &= ~0xFFFF;
221
    AT91C_BASE_SUPC->SUPC_WUIR |= inputs;
222
}
223
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.